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
2da707fe
Commit
2da707fe
authored
Apr 13, 2021
by
Shreyas Agarwal
Committed by
Mayra Cabrera
Apr 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a migration to insert trail plans
parent
35fee074
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
142 additions
and
0 deletions
+142
-0
changelogs/unreleased/322043-insert-plan-trial.yml
changelogs/unreleased/322043-insert-plan-trial.yml
+5
-0
db/post_migrate/20210329102724_add_new_trail_plans.rb
db/post_migrate/20210329102724_add_new_trail_plans.rb
+41
-0
db/schema_migrations/20210329102724
db/schema_migrations/20210329102724
+1
-0
spec/migrations/add_new_trail_plans_spec.rb
spec/migrations/add_new_trail_plans_spec.rb
+95
-0
No files found.
changelogs/unreleased/322043-insert-plan-trial.yml
0 → 100644
View file @
2da707fe
---
title
:
Add a migration to insert trail plans within SAAS for Ultimate and Premium plans
merge_request
:
57814
author
:
type
:
added
db/post_migrate/20210329102724_add_new_trail_plans.rb
0 → 100644
View file @
2da707fe
# frozen_string_literal: true
class
AddNewTrailPlans
<
ActiveRecord
::
Migration
[
6.0
]
class
Plan
<
ActiveRecord
::
Base
self
.
inheritance_column
=
:_type_disabled
has_one
:limits
,
class_name:
'PlanLimits'
def
actual_limits
self
.
limits
||
self
.
build_limits
end
end
class
PlanLimits
<
ActiveRecord
::
Base
self
.
inheritance_column
=
:_type_disabled
belongs_to
:plan
end
def
create_plan_limits
(
plan_limit_name
,
plan
)
plan_limit
=
Plan
.
find_or_initialize_by
(
name:
plan_limit_name
).
actual_limits
.
dup
plan_limit
.
plan
=
plan
plan_limit
.
save!
end
def
up
return
unless
Gitlab
.
dev_env_or_com?
ultimate_trial
=
Plan
.
create!
(
name:
'ultimate_trial'
,
title:
'Ultimate Trial'
)
premium_trial
=
Plan
.
create!
(
name:
'premium_trial'
,
title:
'Premium Trial'
)
create_plan_limits
(
'gold'
,
ultimate_trial
)
create_plan_limits
(
'silver'
,
premium_trial
)
end
def
down
return
unless
Gitlab
.
dev_env_or_com?
Plan
.
where
(
name:
%w(ultimate_trial premium_trial)
).
delete_all
end
end
db/schema_migrations/20210329102724
0 → 100644
View file @
2da707fe
b40c702ea6b2120da6fe11b213064a7a124dbc86bfb2d6785bfd2274c44f1e22
\ No newline at end of file
spec/migrations/add_new_trail_plans_spec.rb
0 → 100644
View file @
2da707fe
# frozen_string_literal: true
require
'spec_helper'
require_migration!
RSpec
.
describe
AddNewTrailPlans
,
:migration
do
describe
'#up'
do
before
do
allow
(
Gitlab
).
to
receive
(
:dev_env_or_com?
).
and_return
true
end
it
'creates 2 entries within the plans table'
do
expect
{
migrate!
}.
to
change
{
AddNewTrailPlans
::
Plan
.
count
}.
by
2
expect
(
AddNewTrailPlans
::
Plan
.
last
(
2
).
pluck
(
:name
)).
to
match_array
(
%w(ultimate_trial premium_trial)
)
end
it
'creates 2 entries for plan limits'
do
expect
{
migrate!
}.
to
change
{
AddNewTrailPlans
::
PlanLimits
.
count
}.
by
2
end
context
'when the plan limits for gold and silver exists'
do
before
do
table
(
:plans
).
create!
(
id:
1
,
name:
'gold'
,
title:
'Gold'
)
table
(
:plan_limits
).
create!
(
id:
1
,
plan_id:
1
,
storage_size_limit:
2000
)
table
(
:plans
).
create!
(
id:
2
,
name:
'silver'
,
title:
'Silver'
)
table
(
:plan_limits
).
create!
(
id:
2
,
plan_id:
2
,
storage_size_limit:
1000
)
end
it
'duplicates the gold and silvers plan limits entries'
do
migrate!
ultimate_plan_limits
=
AddNewTrailPlans
::
Plan
.
find_by
(
name:
'ultimate_trial'
).
limits
expect
(
ultimate_plan_limits
.
storage_size_limit
).
to
be
2000
premium_plan_limits
=
AddNewTrailPlans
::
Plan
.
find_by
(
name:
'premium_trial'
).
limits
expect
(
premium_plan_limits
.
storage_size_limit
).
to
be
1000
end
end
context
'when the instance is not SaaS'
do
before
do
allow
(
Gitlab
).
to
receive
(
:dev_env_or_com?
).
and_return
false
end
it
'does not create plans and plan limits and returns'
do
expect
{
migrate!
}.
not_to
change
{
AddNewTrailPlans
::
Plan
.
count
}
expect
{
migrate!
}.
not_to
change
{
AddNewTrailPlans
::
Plan
.
count
}
end
end
end
describe
'#down'
do
before
do
table
(
:plans
).
create!
(
id:
3
,
name:
'other'
)
table
(
:plan_limits
).
create!
(
plan_id:
3
)
end
context
'when the instance is SaaS'
do
before
do
allow
(
Gitlab
).
to
receive
(
:dev_env_or_com?
).
and_return
true
end
it
'removes the newly added ultimate and premium trial entries'
do
migrate!
expect
{
described_class
.
new
.
down
}.
to
change
{
AddNewTrailPlans
::
Plan
.
count
}.
by
(
-
2
)
expect
(
AddNewTrailPlans
::
Plan
.
find_by
(
name:
'premium_trial'
)).
to
be_nil
expect
(
AddNewTrailPlans
::
Plan
.
find_by
(
name:
'ultimate_trial'
)).
to
be_nil
other_plan
=
AddNewTrailPlans
::
Plan
.
find_by
(
name:
'other'
)
expect
(
other_plan
).
to
be_persisted
expect
(
AddNewTrailPlans
::
PlanLimits
.
count
).
to
eq
(
1
)
expect
(
AddNewTrailPlans
::
PlanLimits
.
first
.
plan_id
).
to
eq
(
other_plan
.
id
)
end
end
context
'when the instance is not SaaS'
do
before
do
allow
(
Gitlab
).
to
receive
(
:dev_env_or_com?
).
and_return
false
table
(
:plans
).
create!
(
id:
1
,
name:
'ultimate_trial'
,
title:
'Ultimate Trial'
)
table
(
:plans
).
create!
(
id:
2
,
name:
'premium_trial'
,
title:
'Premium Trial'
)
table
(
:plan_limits
).
create!
(
id:
1
,
plan_id:
1
)
table
(
:plan_limits
).
create!
(
id:
2
,
plan_id:
2
)
end
it
'does not delete plans and plan limits and returns'
do
migrate!
expect
{
described_class
.
new
.
down
}.
not_to
change
{
AddNewTrailPlans
::
Plan
.
count
}
expect
(
AddNewTrailPlans
::
PlanLimits
.
count
).
to
eq
(
3
)
end
end
end
end
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