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
1efd2241
Commit
1efd2241
authored
May 07, 2021
by
Etienne Baqué
Committed by
Mayra Cabrera
May 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migration to update subscription plans
parent
a7111b39
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
154 additions
and
3 deletions
+154
-3
changelogs/unreleased/321364-update-post-eoa-subscriptions.yml
...elogs/unreleased/321364-update-post-eoa-subscriptions.yml
+5
-0
db/post_migrate/20210303121224_update_gitlab_subscriptions_start_at_post_eoa.rb
...03121224_update_gitlab_subscriptions_start_at_post_eoa.rb
+54
-0
db/schema_migrations/20210303121224
db/schema_migrations/20210303121224
+1
-0
ee/spec/migrations/update_gitlab_subscriptions_start_at_post_eoa_spec.rb
...ons/update_gitlab_subscriptions_start_at_post_eoa_spec.rb
+89
-0
ee/spec/presenters/subscriptions/new_plan_presenter_spec.rb
ee/spec/presenters/subscriptions/new_plan_presenter_spec.rb
+5
-3
No files found.
changelogs/unreleased/321364-update-post-eoa-subscriptions.yml
0 → 100644
View file @
1efd2241
---
title
:
Add migration to update plans on new post-EoA subscriptions
merge_request
:
55625
author
:
type
:
changed
db/post_migrate/20210303121224_update_gitlab_subscriptions_start_at_post_eoa.rb
0 → 100644
View file @
1efd2241
# frozen_string_literal: true
class
UpdateGitlabSubscriptionsStartAtPostEoa
<
ActiveRecord
::
Migration
[
6.0
]
UPDATE_BATCH_SIZE
=
100
disable_ddl_transaction!
class
Plan
<
ActiveRecord
::
Base
self
.
table_name
=
'plans'
self
.
inheritance_column
=
:_type_disabled
end
class
GitlabSubscription
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'gitlab_subscriptions'
self
.
inheritance_column
=
:_type_disabled
EOA_ROLLOUT_DATE
=
'2021-01-26'
scope
:with_plan
,
->
(
from_plan
)
do
where
(
"start_date >= ? AND hosted_plan_id = ?"
,
EOA_ROLLOUT_DATE
,
from_plan
.
id
)
end
end
def
up
return
unless
Gitlab
.
com?
silver_plan
=
Plan
.
find_by
(
name:
'silver'
)
gold_plan
=
Plan
.
find_by
(
name:
'gold'
)
premium_plan
=
Plan
.
find_by
(
name:
'premium'
)
ultimate_plan
=
Plan
.
find_by
(
name:
'ultimate'
)
# Silver to Premium
update_hosted_plan_for_subscription
(
from_plan:
silver_plan
,
to_plan:
premium_plan
)
# Gold to Ultimate
update_hosted_plan_for_subscription
(
from_plan:
gold_plan
,
to_plan:
ultimate_plan
)
end
def
down
# no-op
end
private
def
update_hosted_plan_for_subscription
(
from_plan
:,
to_plan
:)
return
unless
from_plan
&&
to_plan
GitlabSubscription
.
with_plan
(
from_plan
).
each_batch
(
of:
UPDATE_BATCH_SIZE
)
do
|
batch
|
batch
.
update_all
(
hosted_plan_id:
to_plan
.
id
)
end
end
end
db/schema_migrations/20210303121224
0 → 100644
View file @
1efd2241
cef2421a6885cb8b28d34388af6c79c4be1564dfd5fae2efcb35622d511eb8c0
\ No newline at end of file
ee/spec/migrations/update_gitlab_subscriptions_start_at_post_eoa_spec.rb
0 → 100644
View file @
1efd2241
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20210303121224_update_gitlab_subscriptions_start_at_post_eoa.rb'
)
RSpec
.
describe
UpdateGitlabSubscriptionsStartAtPostEoa
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:eoa_rollout_date
)
{
described_class
::
GitlabSubscription
::
EOA_ROLLOUT_DATE
.
to_date
}
let
(
:gitlab_subscriptions_table
)
{
table
(
:gitlab_subscriptions
)
}
let
(
:plans_table
)
{
table
(
:plans
)
}
let
(
:namespaces_table
)
{
table
(
:namespaces
)
}
let!
(
:namespace_one
)
{
namespaces_table
.
create!
(
name:
'namespace1'
,
path:
'path1'
)
}
let!
(
:namespace_two
)
{
namespaces_table
.
create!
(
name:
'namespace2'
,
path:
'path2'
)
}
let!
(
:free_plan
)
{
plans_table
.
create!
(
name:
'free'
)
}
let!
(
:silver_plan
)
{
plans_table
.
create!
(
name:
'silver'
)
}
let!
(
:gold_plan
)
{
plans_table
.
create!
(
name:
'gold'
)
}
let!
(
:premium_plan
)
{
plans_table
.
create!
(
name:
'premium'
)
}
let!
(
:ultimate_plan
)
{
plans_table
.
create!
(
name:
'ultimate'
)
}
describe
'#up'
do
context
'when not on GitLab.com'
do
before
do
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
(
false
)
end
it
'does not do any update'
do
expect
(
migration
).
not_to
receive
(
:update_hosted_plan_for_subscription
)
migration
.
up
end
end
context
'when on Gitlab.com'
do
before
do
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
end
it
'updates the silver and gold post-EoA subscriptions'
do
silver_sub
=
gitlab_subscriptions_table
.
create!
(
start_date:
eoa_rollout_date
+
2
.
days
,
hosted_plan_id:
silver_plan
.
id
,
namespace_id:
namespace_two
.
id
)
gold_sub
=
gitlab_subscriptions_table
.
create!
(
start_date:
eoa_rollout_date
+
5
.
days
,
hosted_plan_id:
gold_plan
.
id
,
namespace_id:
namespace_one
.
id
)
migration
.
up
expect
(
silver_sub
.
reload
.
hosted_plan_id
).
to
eq
(
premium_plan
.
id
)
expect
(
gold_sub
.
reload
.
hosted_plan_id
).
to
eq
(
ultimate_plan
.
id
)
end
context
'when a subscription occurred before eoa date'
do
it
'is not being updated'
do
silver_sub
=
gitlab_subscriptions_table
.
create!
(
start_date:
eoa_rollout_date
-
3
.
days
,
hosted_plan_id:
silver_plan
.
id
,
namespace_id:
namespace_two
.
id
)
migration
.
up
expect
(
silver_sub
.
reload
.
hosted_plan_id
).
to
eq
(
silver_plan
.
id
)
end
end
context
'when a subscription other than gold and silver was bought after eoa date'
do
it
'is not being updated'
do
free_sub
=
gitlab_subscriptions_table
.
create!
(
start_date:
eoa_rollout_date
+
2
.
days
,
hosted_plan_id:
free_plan
.
id
,
namespace_id:
namespace_one
.
id
)
migration
.
up
expect
(
free_sub
.
reload
.
hosted_plan_id
).
to
eq
(
free_plan
.
id
)
end
end
end
end
end
ee/spec/presenters/subscriptions/new_plan_presenter_spec.rb
View file @
1efd2241
...
...
@@ -7,9 +7,11 @@ RSpec.describe Subscriptions::NewPlanPresenter do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:legacy_name
,
:new_title
)
do
'bronze'
|
'Bronze'
'silver'
|
'Premium (Formerly Silver)'
'gold'
|
'Ultimate (Formerly Gold)'
'bronze'
|
'Bronze'
'silver'
|
'Premium (Formerly Silver)'
'gold'
|
'Ultimate (Formerly Gold)'
'premium'
|
'Premium'
'ultimate'
|
'Ultimate'
end
with_them
do
...
...
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