Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1f0e9f79
Commit
1f0e9f79
authored
Jan 14, 2021
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab master
parents
bc684654
843f965c
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
312 additions
and
20 deletions
+312
-20
.gitlab/issue_templates/Design Sprint.md
.gitlab/issue_templates/Design Sprint.md
+203
-0
changelogs/unreleased/290008-fix-background-migration-arguments.yml
.../unreleased/290008-fix-background-migration-arguments.yml
+5
-0
db/post_migrate/20201207165956_remove_duplicate_services.rb
db/post_migrate/20201207165956_remove_duplicate_services.rb
+1
-14
db/post_migrate/20210112143418_remove_duplicate_services2.rb
db/post_migrate/20210112143418_remove_duplicate_services2.rb
+29
-0
db/schema_migrations/20210112143418
db/schema_migrations/20210112143418
+1
-0
ee/app/services/gitlab_subscriptions/apply_trial_service.rb
ee/app/services/gitlab_subscriptions/apply_trial_service.rb
+10
-0
ee/spec/services/gitlab_subscriptions/apply_trial_service_spec.rb
...services/gitlab_subscriptions/apply_trial_service_spec.rb
+57
-0
lib/gitlab/background_migration/remove_duplicate_services.rb
lib/gitlab/background_migration/remove_duplicate_services.rb
+1
-1
spec/lib/gitlab/background_migration/remove_duplicate_services_spec.rb
...ab/background_migration/remove_duplicate_services_spec.rb
+3
-3
spec/migrations/20210112143418_remove_duplicate_services2_spec.rb
...rations/20210112143418_remove_duplicate_services2_spec.rb
+2
-2
No files found.
.gitlab/issue_templates/Design Sprint.md
0 → 100644
View file @
1f0e9f79
This diff is collapsed.
Click to expand it.
changelogs/unreleased/290008-fix-background-migration-arguments.yml
0 → 100644
View file @
1f0e9f79
---
title
:
Fix argument type for background migration
merge_request
:
51475
author
:
type
:
fixed
db/post_migrate/20201207165956_remove_duplicate_services.rb
View file @
1f0e9f79
# frozen_string_literal: true
# frozen_string_literal: true
class
RemoveDuplicateServices
<
ActiveRecord
::
Migration
[
6.0
]
class
RemoveDuplicateServices
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DOWNTIME
=
false
INTERVAL
=
2
.
minutes
BATCH_SIZE
=
5_000
MIGRATION
=
'RemoveDuplicateServices'
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
project_ids_with_duplicates
=
Gitlab
::
BackgroundMigration
::
RemoveDuplicateServices
::
Service
.
project_ids_with_duplicates
# noop, replaced by 20210112143418_remove_duplicate_services.rb
project_ids_with_duplicates
.
each_batch
(
of:
BATCH_SIZE
,
column: :project_id
)
do
|
batch
,
index
|
migrate_in
(
INTERVAL
*
index
,
MIGRATION
,
batch
.
pluck
(
:project_id
)
)
end
end
end
def
down
def
down
...
...
db/post_migrate/20210112143418_remove_duplicate_services2.rb
0 → 100644
View file @
1f0e9f79
# frozen_string_literal: true
# This replaces the previous post-deployment migration 20201207165956_remove_duplicate_services_spec.rb,
# we have to run this again due to a bug in how we were receiving the arguments in the background migration.
class
RemoveDuplicateServices2
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
INTERVAL
=
2
.
minutes
BATCH_SIZE
=
5_000
MIGRATION
=
'RemoveDuplicateServices'
disable_ddl_transaction!
def
up
project_ids_with_duplicates
=
Gitlab
::
BackgroundMigration
::
RemoveDuplicateServices
::
Service
.
project_ids_with_duplicates
project_ids_with_duplicates
.
each_batch
(
of:
BATCH_SIZE
,
column: :project_id
)
do
|
batch
,
index
|
migrate_in
(
INTERVAL
*
index
,
MIGRATION
,
batch
.
pluck
(
:project_id
)
)
end
end
def
down
end
end
db/schema_migrations/20210112143418
0 → 100644
View file @
1f0e9f79
05d45e25ab9ef1565c04ca6515e0b01f2f98c5e98b1eeb09fa9dd43ebbe3c4d0
\ No newline at end of file
ee/app/services/gitlab_subscriptions/apply_trial_service.rb
View file @
1f0e9f79
...
@@ -6,6 +6,9 @@ module GitlabSubscriptions
...
@@ -6,6 +6,9 @@ module GitlabSubscriptions
response
=
client
.
generate_trial
(
apply_trial_params
)
response
=
client
.
generate_trial
(
apply_trial_params
)
if
response
[
:success
]
if
response
[
:success
]
namespace_id
=
apply_trial_params
.
dig
(
:trial_user
,
:namespace_id
)
record_onboarding_progress
(
namespace_id
)
if
namespace_id
{
success:
true
}
{
success:
true
}
else
else
{
success:
false
,
errors:
response
.
dig
(
:data
,
:errors
)
}
{
success:
false
,
errors:
response
.
dig
(
:data
,
:errors
)
}
...
@@ -17,5 +20,12 @@ module GitlabSubscriptions
...
@@ -17,5 +20,12 @@ module GitlabSubscriptions
def
client
def
client
Gitlab
::
SubscriptionPortal
::
Client
Gitlab
::
SubscriptionPortal
::
Client
end
end
def
record_onboarding_progress
(
namespace_id
)
namespace
=
Namespace
.
find_by
(
id:
namespace_id
)
# rubocop: disable CodeReuse/ActiveRecord
return
unless
namespace
OnboardingProgressService
.
new
(
namespace
).
execute
(
action: :trial_started
)
end
end
end
end
end
ee/spec/services/gitlab_subscriptions/apply_trial_service_spec.rb
0 → 100644
View file @
1f0e9f79
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
GitlabSubscriptions
::
ApplyTrialService
do
subject
(
:execute
)
{
described_class
.
new
.
execute
(
apply_trial_params
)
}
let_it_be
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:apply_trial_params
)
do
{
trial_user:
{
namespace_id:
namespace
.
id
}
}
end
describe
'#execute'
do
before
do
allow
(
Gitlab
::
SubscriptionPortal
::
Client
).
to
receive
(
:generate_trial
).
and_return
(
response
)
end
context
'trial applied successfully'
do
let
(
:response
)
{
{
success:
true
}}
it
'returns success: true'
do
expect
(
execute
).
to
eq
({
success:
true
})
end
it
'records a namespace onboarding progress action'
do
expect_next_instance_of
(
OnboardingProgressService
)
do
|
service
|
expect
(
service
).
to
receive
(
:execute
).
with
(
action: :trial_started
)
end
execute
end
end
context
'error while applying the trial'
do
let
(
:response
)
{
{
success:
false
,
data:
{
errors:
[
'some error'
]
}
}}
it
'returns success: false with errors'
do
expected_response
=
{
success:
false
,
errors:
[
'some error'
]
}
expect
(
execute
).
to
eq
(
expected_response
)
end
it
'does not record a namespace onboarding progress action'
do
expect
(
OnboardingProgressService
).
not_to
receive
(
:new
)
execute
end
end
end
end
lib/gitlab/background_migration/remove_duplicate_services.rb
View file @
1f0e9f79
...
@@ -29,7 +29,7 @@ module Gitlab
...
@@ -29,7 +29,7 @@ module Gitlab
end
end
end
end
def
perform
(
project_ids
)
def
perform
(
*
project_ids
)
types_with_duplicates
=
Service
.
types_with_duplicates
(
project_ids
).
pluck
(
:project_id
,
:type
)
types_with_duplicates
=
Service
.
types_with_duplicates
(
project_ids
).
pluck
(
:project_id
,
:type
)
types_with_duplicates
.
each
do
|
project_id
,
type
|
types_with_duplicates
.
each
do
|
project_id
,
type
|
...
...
spec/lib/gitlab/background_migration/remove_duplicate_services_spec.rb
View file @
1f0e9f79
...
@@ -82,7 +82,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicateServices, :migration,
...
@@ -82,7 +82,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicateServices, :migration,
end
end
expect
do
expect
do
subject
.
perform
(
[
project2
.
id
,
project3
.
id
]
)
subject
.
perform
(
project2
.
id
,
project3
.
id
)
end
.
to
change
{
services
.
count
}.
from
(
21
).
to
(
12
)
end
.
to
change
{
services
.
count
}.
from
(
21
).
to
(
12
)
services1
=
services
.
where
(
project_id:
project1
.
id
)
services1
=
services
.
where
(
project_id:
project1
.
id
)
...
@@ -109,13 +109,13 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicateServices, :migration,
...
@@ -109,13 +109,13 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicateServices, :migration,
it
'does not delete services without duplicates'
do
it
'does not delete services without duplicates'
do
expect
do
expect
do
subject
.
perform
(
[
project1
.
id
,
project4
.
id
]
)
subject
.
perform
(
project1
.
id
,
project4
.
id
)
end
.
not_to
change
{
services
.
count
}
end
.
not_to
change
{
services
.
count
}
end
end
it
'only deletes duplicate services for the current batch'
do
it
'only deletes duplicate services for the current batch'
do
expect
do
expect
do
subject
.
perform
(
[
project2
.
id
]
)
subject
.
perform
(
project2
.
id
)
end
.
to
change
{
services
.
count
}.
by
(
-
3
)
end
.
to
change
{
services
.
count
}.
by
(
-
3
)
end
end
end
end
spec/migrations/202
01207165956_remove_duplicate_services
_spec.rb
→
spec/migrations/202
10112143418_remove_duplicate_services2
_spec.rb
View file @
1f0e9f79
# frozen_string_literal: true
# frozen_string_literal: true
require
'spec_helper'
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'202
01207165956_remove_duplicate_services
.rb'
)
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'202
10112143418_remove_duplicate_services2
.rb'
)
RSpec
.
describe
RemoveDuplicateServices
do
RSpec
.
describe
RemoveDuplicateServices
2
do
let_it_be
(
:namespaces
)
{
table
(
:namespaces
)
}
let_it_be
(
:namespaces
)
{
table
(
:namespaces
)
}
let_it_be
(
:projects
)
{
table
(
:projects
)
}
let_it_be
(
:projects
)
{
table
(
:projects
)
}
let_it_be
(
:services
)
{
table
(
:services
)
}
let_it_be
(
:services
)
{
table
(
:services
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment