pg_trunk 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +4 -15
  3. data/CHANGELOG.md +21 -0
  4. data/README.md +3 -1
  5. data/lib/pg_trunk/core/operation/attributes.rb +1 -1
  6. data/lib/pg_trunk/core/railtie/custom_types.rb +5 -6
  7. data/lib/pg_trunk/operations/check_constraints/add_check_constraint.rb +42 -33
  8. data/lib/pg_trunk/operations/check_constraints/drop_check_constraint.rb +51 -40
  9. data/lib/pg_trunk/operations/check_constraints/rename_check_constraint.rb +39 -30
  10. data/lib/pg_trunk/operations/check_constraints/validate_check_constraint.rb +28 -21
  11. data/lib/pg_trunk/operations/composite_types/change_composite_type.rb +59 -50
  12. data/lib/pg_trunk/operations/composite_types/create_composite_type.rb +23 -19
  13. data/lib/pg_trunk/operations/composite_types/drop_composite_type.rb +48 -43
  14. data/lib/pg_trunk/operations/composite_types/rename_composite_type.rb +15 -12
  15. data/lib/pg_trunk/operations/domains/change_domain.rb +53 -47
  16. data/lib/pg_trunk/operations/domains/create_domain.rb +28 -25
  17. data/lib/pg_trunk/operations/domains/drop_domain.rb +50 -41
  18. data/lib/pg_trunk/operations/domains/rename_domain.rb +17 -12
  19. data/lib/pg_trunk/operations/enums/change_enum.rb +37 -32
  20. data/lib/pg_trunk/operations/enums/create_enum.rb +23 -20
  21. data/lib/pg_trunk/operations/enums/drop_enum.rb +50 -39
  22. data/lib/pg_trunk/operations/enums/rename_enum.rb +17 -12
  23. data/lib/pg_trunk/operations/foreign_keys/add_foreign_key.rb +58 -49
  24. data/lib/pg_trunk/operations/foreign_keys/drop_foreign_key.rb +57 -48
  25. data/lib/pg_trunk/operations/foreign_keys/rename_foreign_key.rb +38 -29
  26. data/lib/pg_trunk/operations/functions/change_function.rb +53 -47
  27. data/lib/pg_trunk/operations/functions/create_function.rb +75 -64
  28. data/lib/pg_trunk/operations/functions/drop_function.rb +78 -65
  29. data/lib/pg_trunk/operations/functions/rename_function.rb +29 -22
  30. data/lib/pg_trunk/operations/materialized_views/change_materialized_view.rb +65 -55
  31. data/lib/pg_trunk/operations/materialized_views/create_materialized_view.rb +82 -71
  32. data/lib/pg_trunk/operations/materialized_views/drop_materialized_view.rb +59 -46
  33. data/lib/pg_trunk/operations/materialized_views/refresh_materialized_view.rb +29 -24
  34. data/lib/pg_trunk/operations/materialized_views/rename_materialized_view.rb +29 -22
  35. data/lib/pg_trunk/operations/procedures/change_procedure.rb +53 -46
  36. data/lib/pg_trunk/operations/procedures/create_procedure.rb +63 -52
  37. data/lib/pg_trunk/operations/procedures/drop_procedure.rb +56 -45
  38. data/lib/pg_trunk/operations/procedures/rename_procedure.rb +29 -22
  39. data/lib/pg_trunk/operations/rules/base.rb +77 -0
  40. data/lib/pg_trunk/operations/rules/create_rule.rb +155 -0
  41. data/lib/pg_trunk/operations/rules/drop_rule.rb +94 -0
  42. data/lib/pg_trunk/operations/rules/rename_rule.rb +62 -0
  43. data/lib/pg_trunk/operations/rules.rb +13 -0
  44. data/lib/pg_trunk/operations/sequences/base.rb +79 -0
  45. data/lib/pg_trunk/operations/sequences/change_sequence.rb +142 -0
  46. data/lib/pg_trunk/operations/sequences/create_sequence.rb +180 -0
  47. data/lib/pg_trunk/operations/sequences/drop_sequence.rb +82 -0
  48. data/lib/pg_trunk/operations/sequences/rename_sequence.rb +64 -0
  49. data/lib/pg_trunk/operations/sequences.rb +14 -0
  50. data/lib/pg_trunk/operations/statistics/create_statistics.rb +67 -56
  51. data/lib/pg_trunk/operations/statistics/drop_statistics.rb +64 -53
  52. data/lib/pg_trunk/operations/statistics/rename_statistics.rb +18 -13
  53. data/lib/pg_trunk/operations/triggers/change_trigger.rb +23 -18
  54. data/lib/pg_trunk/operations/triggers/create_trigger.rb +63 -54
  55. data/lib/pg_trunk/operations/triggers/drop_trigger.rb +55 -46
  56. data/lib/pg_trunk/operations/triggers/rename_trigger.rb +51 -48
  57. data/lib/pg_trunk/operations/views/change_view.rb +47 -38
  58. data/lib/pg_trunk/operations/views/create_view.rb +56 -45
  59. data/lib/pg_trunk/operations/views/drop_view.rb +59 -46
  60. data/lib/pg_trunk/operations/views/rename_view.rb +27 -20
  61. data/lib/pg_trunk/operations.rb +2 -0
  62. data/lib/pg_trunk/version.rb +1 -1
  63. data/pg_trunk.gemspec +0 -1
  64. data/spec/operations/rules/create_rule_spec.rb +119 -0
  65. data/spec/operations/rules/drop_rule_spec.rb +117 -0
  66. data/spec/operations/rules/rename_rule_spec.rb +148 -0
  67. data/spec/operations/sequences/change_sequence_spec.rb +134 -0
  68. data/spec/operations/sequences/create_sequence_spec.rb +156 -0
  69. data/spec/operations/sequences/drop_sequence_spec.rb +102 -0
  70. data/spec/operations/sequences/rename_sequence_spec.rb +100 -0
  71. metadata +22 -68
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe ActiveRecord::Migration, "#rename_rule" do
4
+ before_all do
5
+ run_migration <<~RUBY
6
+ create_table :users do |t|
7
+ t.string :name
8
+ end
9
+ RUBY
10
+ end
11
+ before { run_migration(old_snippet) }
12
+
13
+ context "when a rule was named" do
14
+ let(:old_snippet) do
15
+ <<~RUBY
16
+ create_rule "users", "prevent_insertion" do |r|
17
+ r.event :insert
18
+ r.kind :instead
19
+ r.comment "Prevent insertion to users"
20
+ end
21
+ RUBY
22
+ end
23
+
24
+ context "with a new name" do
25
+ let(:migration) do
26
+ <<~RUBY
27
+ rename_rule "users", "prevent_insertion", to: "do_nothing"
28
+ RUBY
29
+ end
30
+ let(:new_snippet) do
31
+ <<~RUBY
32
+ create_rule "users", "do_nothing" do |r|
33
+ r.event :insert
34
+ r.kind :instead
35
+ r.comment "Prevent insertion to users"
36
+ end
37
+ RUBY
38
+ end
39
+
40
+ its(:execution) { is_expected.to remove(old_snippet).from_schema }
41
+ its(:execution) { is_expected.to insert(new_snippet).into_schema }
42
+ its(:inversion) { is_expected.not_to change_schema }
43
+ end
44
+
45
+ context "with the same name" do
46
+ let(:migration) do
47
+ <<~RUBY
48
+ rename_rule "users", "prevent_insertion", to: "prevent_insertion"
49
+ RUBY
50
+ end
51
+
52
+ it { is_expected.to fail_validation.because(/new name must be different/i) }
53
+ end
54
+
55
+ context "without new name" do
56
+ let(:migration) do
57
+ <<~RUBY
58
+ rename_rule "users", "prevent_insertion" do |r|
59
+ r.event :insert
60
+ r.kind :instead
61
+ end
62
+ RUBY
63
+ end
64
+ let(:new_snippet) do
65
+ <<~RUBY
66
+ create_rule "users" do |r|
67
+ r.event :insert
68
+ r.kind :instead
69
+ r.comment "Prevent insertion to users"
70
+ end
71
+ RUBY
72
+ end
73
+
74
+ its(:execution) { is_expected.to remove(old_snippet).from_schema }
75
+ its(:execution) { is_expected.to insert(new_snippet).into_schema }
76
+ its(:inversion) { is_expected.not_to change_schema }
77
+ end
78
+
79
+ context "when absent name can't be generated from kind/event" do
80
+ let(:migration) do
81
+ <<~RUBY
82
+ rename_rule "users", "prevent_insertion"
83
+ RUBY
84
+ end
85
+
86
+ it { is_expected.to fail_validation.because(/new name can't be blank/i) }
87
+ end
88
+ end
89
+
90
+ context "when a rule was anonymous" do
91
+ let(:old_snippet) do
92
+ <<~RUBY
93
+ create_rule "users" do |r|
94
+ r.event :insert
95
+ r.kind :instead
96
+ r.comment "Prevent insertion to users"
97
+ end
98
+ RUBY
99
+ end
100
+
101
+ context "with a new name" do
102
+ let(:migration) do
103
+ <<~RUBY
104
+ rename_rule "users", to: "do_nothing" do |r|
105
+ r.event :insert
106
+ r.kind :instead
107
+ end
108
+ RUBY
109
+ end
110
+ let(:new_snippet) do
111
+ <<~RUBY
112
+ create_rule "users", "do_nothing" do |r|
113
+ r.event :insert
114
+ r.kind :instead
115
+ r.comment "Prevent insertion to users"
116
+ end
117
+ RUBY
118
+ end
119
+
120
+ its(:execution) { is_expected.to remove(old_snippet).from_schema }
121
+ its(:execution) { is_expected.to insert(new_snippet).into_schema }
122
+ its(:inversion) { is_expected.not_to change_schema }
123
+ end
124
+
125
+ context "without new name" do
126
+ let(:migration) do
127
+ <<~RUBY
128
+ rename_rule "users" do |r|
129
+ r.event :insert
130
+ r.kind :instead
131
+ end
132
+ RUBY
133
+ end
134
+
135
+ it { is_expected.to fail_validation.because(/new name must be different/i) }
136
+ end
137
+
138
+ context "when absent name can't be generated" do
139
+ let(:migration) do
140
+ <<~RUBY
141
+ rename_rule "users", to: "do_nothing"
142
+ RUBY
143
+ end
144
+
145
+ it { is_expected.to fail_validation.because(/name can't be blank/i) }
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe ActiveRecord::Migration, "#change_sequence" do
4
+ before { run_migration(old_snippet) }
5
+
6
+ let(:old_snippet) do
7
+ <<~RUBY
8
+ create_sequence "global_num", as: "integer" do |s|
9
+ s.increment_by 2
10
+ s.min_value 0
11
+ s.max_value 2000
12
+ s.start_with 1
13
+ s.cache 10
14
+ s.cycle true
15
+ s.comment "Sequence for global numbers (odds then evens)"
16
+ end
17
+ RUBY
18
+ end
19
+
20
+ context "with reversible changes" do
21
+ let(:migration) do
22
+ <<~RUBY
23
+ change_sequence "global_num" do |s|
24
+ s.type "bigint", from: "integer"
25
+ s.increment_by 3, from: 2
26
+ s.min_value 1, from: 0
27
+ s.max_value 3000, from: 2000
28
+ s.start_with 2, from: 1
29
+ s.cache 20, from: 10
30
+ s.cycle false
31
+ s.comment "Global numbers", from: "Sequence for global numbers (odds then evens)"
32
+ end
33
+ RUBY
34
+ end
35
+ let(:new_snippet) do
36
+ <<~RUBY
37
+ create_sequence "global_num" do |s|
38
+ s.increment_by 3
39
+ s.max_value 3000
40
+ s.start_with 2
41
+ s.cache 20
42
+ s.comment "Global numbers"
43
+ end
44
+ RUBY
45
+ end
46
+
47
+ its(:execution) { is_expected.to remove(old_snippet).from_schema }
48
+ its(:execution) { is_expected.to insert(new_snippet).into_schema }
49
+ its(:inversion) { is_expected.not_to change_schema }
50
+ end
51
+
52
+ context "with irreversible changes" do
53
+ let(:migration) do
54
+ <<~RUBY
55
+ change_sequence "global_num" do |s|
56
+ s.type "bigint"
57
+ s.increment_by 3
58
+ s.min_value 1
59
+ s.max_value 3000
60
+ s.start_with 2
61
+ s.cache 20
62
+ s.cycle false
63
+ s.comment "Global numbers"
64
+ end
65
+ RUBY
66
+ end
67
+ let(:new_snippet) do
68
+ <<~RUBY
69
+ create_sequence "global_num" do |s|
70
+ s.increment_by 3
71
+ s.max_value 3000
72
+ s.start_with 2
73
+ s.cache 20
74
+ s.comment "Global numbers"
75
+ end
76
+ RUBY
77
+ end
78
+
79
+ its(:execution) { is_expected.to remove(old_snippet).from_schema }
80
+ its(:execution) { is_expected.to insert(new_snippet).into_schema }
81
+ it { is_expected.to be_irreversible.because_of(/undefined values to revert/i) }
82
+ end
83
+
84
+ context "when sequence was absent" do
85
+ let(:old_snippet) { "" }
86
+
87
+ context "without the `:if_exists` option" do
88
+ let(:migration) do
89
+ <<~RUBY
90
+ change_sequence "global_num" do |s|
91
+ s.comment "Global numbers"
92
+ end
93
+ RUBY
94
+ end
95
+
96
+ its(:execution) { is_expected.to raise_error(StandardError) }
97
+ end
98
+
99
+ context "with the `if_exists: true` option" do
100
+ let(:migration) do
101
+ <<~RUBY
102
+ change_sequence "global_num", if_exists: true do |s|
103
+ s.comment "Global numbers"
104
+ end
105
+ RUBY
106
+ end
107
+
108
+ its(:execution) { is_expected.not_to change_schema }
109
+ it { is_expected.to be_irreversible.because_of(/if_exists: true/i) }
110
+ end
111
+ end
112
+
113
+ context "without changes" do
114
+ let(:migration) do
115
+ <<~RUBY
116
+ change_sequence "global_num"
117
+ RUBY
118
+ end
119
+
120
+ it { is_expected.to fail_validation.because(/changes can't be blank/i) }
121
+ end
122
+
123
+ context "without a name" do
124
+ let(:migration) do
125
+ <<~RUBY
126
+ change_sequence do |s|
127
+ s.comment "Global numbers"
128
+ end
129
+ RUBY
130
+ end
131
+
132
+ it { is_expected.to fail_validation.because(/name can't be blank/i) }
133
+ end
134
+ end
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe ActiveRecord::Migration, "#create_sequence" do
4
+ before_all do
5
+ run_migration <<~RUBY
6
+ create_schema :app
7
+
8
+ create_table :customers do |t|
9
+ t.bigint :global_num
10
+ end
11
+ RUBY
12
+ end
13
+
14
+ context "with a minimal definition" do
15
+ let(:migration) do
16
+ <<~RUBY
17
+ create_sequence "app.global_num"
18
+ RUBY
19
+ end
20
+
21
+ its(:execution) { is_expected.to insert(migration).into_schema }
22
+ its(:inversion) { is_expected.not_to change_schema }
23
+ end
24
+
25
+ context "with a table-agnostic definition" do
26
+ let(:migration) do
27
+ <<~RUBY
28
+ create_sequence "app.global_num", as: "integer" do |s|
29
+ s.increment_by 2
30
+ s.min_value 0
31
+ s.max_value 2000
32
+ s.start_with 1
33
+ s.cache 10
34
+ s.cycle true
35
+ s.comment "Sequence for global numbers (odds then evens)"
36
+ end
37
+ RUBY
38
+ end
39
+
40
+ its(:execution) { is_expected.to insert(migration).into_schema }
41
+ its(:inversion) { is_expected.not_to change_schema }
42
+ end
43
+
44
+ context "with a column-specific definition" do
45
+ let(:migration) do
46
+ <<~RUBY
47
+ create_sequence "global_num" do |s|
48
+ s.owned_by "customers", "global_num"
49
+ s.increment_by 2
50
+ s.min_value 0
51
+ s.max_value 2000
52
+ s.start_with 1
53
+ s.cache 10
54
+ s.cycle true
55
+ s.comment "Sequence for customers global_num"
56
+ end
57
+ RUBY
58
+ end
59
+
60
+ its(:execution) { is_expected.to insert(migration).into_schema }
61
+ its(:inversion) { is_expected.not_to change_schema }
62
+ end
63
+
64
+ context "when the sequence existed" do
65
+ before { run_migration(migration) }
66
+
67
+ context "without the `:if_not_exists` option" do
68
+ let(:migration) do
69
+ <<~RUBY
70
+ create_sequence "app.global_num"
71
+ RUBY
72
+ end
73
+
74
+ its(:execution) { is_expected.to raise_error(StandardError) }
75
+ end
76
+
77
+ context "with the `if_not_exists: true` option" do
78
+ let(:migration) do
79
+ <<~RUBY
80
+ create_sequence "app.global_num", if_not_exists: true
81
+ RUBY
82
+ end
83
+ let(:snippet) do
84
+ <<~RUBY
85
+ create_sequence "app.global_num"
86
+ RUBY
87
+ end
88
+
89
+ its(:execution) { is_expected.not_to change_schema }
90
+ it { is_expected.to be_irreversible.because_of(/if_not_exists: true/i) }
91
+ end
92
+ end
93
+
94
+ context "with a zero increment" do
95
+ let(:migration) do
96
+ <<~RUBY
97
+ create_sequence "app.global_number", increment_by: 0
98
+ RUBY
99
+ end
100
+
101
+ it { is_expected.to fail_validation.because(/increment must not be zero/i) }
102
+ end
103
+
104
+ context "with invalid min..max range" do
105
+ let(:migration) do
106
+ <<~RUBY
107
+ create_sequence "app.global_number", min_value: 2, max_value: 1
108
+ RUBY
109
+ end
110
+
111
+ it { is_expected.to fail_validation.because(/min value must not exceed max value/i) }
112
+ end
113
+
114
+ context "with start value out of min..max range" do
115
+ let(:migration) do
116
+ <<~RUBY
117
+ create_sequence "app.global_number",
118
+ min_value: 0,
119
+ max_value: 10,
120
+ start_with: -1
121
+ RUBY
122
+ end
123
+
124
+ it { is_expected.to fail_validation.because(/start value cannot be less than min value/i) }
125
+ end
126
+
127
+ context "with a zero cache" do
128
+ let(:migration) do
129
+ <<~RUBY
130
+ create_sequence "app.global_number", cache: 0
131
+ RUBY
132
+ end
133
+
134
+ it { is_expected.to fail_validation.because(/cache must be greater than or equal to 1/i) }
135
+ end
136
+
137
+ context "with a wrong type" do
138
+ let(:migration) do
139
+ <<~RUBY
140
+ create_sequence "app.global_number", as: "text"
141
+ RUBY
142
+ end
143
+
144
+ its(:execution) { is_expected.to raise_error(StandardError) }
145
+ end
146
+
147
+ context "without a name" do
148
+ let(:migration) do
149
+ <<~RUBY
150
+ create_sequence
151
+ RUBY
152
+ end
153
+
154
+ it { is_expected.to fail_validation.because(/name can't be blank/i) }
155
+ end
156
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe ActiveRecord::Migration, "#drop_sequence" do
4
+ before_all { run_migration("create_schema :app") }
5
+ before { run_migration(old_snippet) }
6
+
7
+ let(:old_snippet) do
8
+ <<~RUBY
9
+ create_sequence "app.global_num", as: "integer" do |s|
10
+ s.increment_by 2
11
+ s.min_value 0
12
+ s.max_value 2000
13
+ s.start_with 1
14
+ s.cache 10
15
+ s.cycle true
16
+ s.comment "Sequence for global numbers (odds then evens)"
17
+ end
18
+ RUBY
19
+ end
20
+
21
+ context "with a full definition" do
22
+ let(:migration) do
23
+ <<~RUBY
24
+ drop_sequence "app.global_num", as: "integer" do |s|
25
+ s.increment_by 2
26
+ s.min_value 0
27
+ s.max_value 2000
28
+ s.start_with 1
29
+ s.cache 10
30
+ s.cycle true
31
+ s.comment "Sequence for global numbers (odds then evens)"
32
+ end
33
+ RUBY
34
+ end
35
+
36
+ its(:execution) { is_expected.to remove(old_snippet).from_schema }
37
+ its(:inversion) { is_expected.not_to change_schema }
38
+ end
39
+
40
+ context "with a minimal definition" do
41
+ let(:migration) do
42
+ <<~RUBY
43
+ drop_sequence "app.global_num"
44
+ RUBY
45
+ end
46
+ let(:new_snippet) do
47
+ <<~RUBY
48
+ create_sequence "app.global_num"
49
+ RUBY
50
+ end
51
+
52
+ its(:execution) { is_expected.to remove(old_snippet).from_schema }
53
+ its(:inversion) { is_expected.to remove(old_snippet).from_schema }
54
+ its(:inversion) { is_expected.to insert(new_snippet).into_schema }
55
+ end
56
+
57
+ context "when the sequence was absent" do
58
+ before { run_migration(migration) }
59
+
60
+ context "without the `:if_exists` option" do
61
+ let(:migration) do
62
+ <<~RUBY
63
+ drop_sequence "app.global_num"
64
+ RUBY
65
+ end
66
+
67
+ its(:execution) { is_expected.to raise_error(StandardError) }
68
+ end
69
+
70
+ context "with the `if_exists: true` option" do
71
+ let(:migration) do
72
+ <<~RUBY
73
+ drop_sequence "app.global_num", if_exists: true
74
+ RUBY
75
+ end
76
+
77
+ its(:execution) { is_expected.not_to change_schema }
78
+ it { is_expected.to be_irreversible.because_of(/if_exists: true/i) }
79
+ end
80
+ end
81
+
82
+ context "with the force: :cascade option" do
83
+ let(:migration) do
84
+ <<~RUBY
85
+ drop_sequence "app.global_num", force: :cascade
86
+ RUBY
87
+ end
88
+
89
+ its(:execution) { is_expected.to remove(old_snippet).from_schema }
90
+ it { is_expected.to be_irreversible.because_of(/force: :cascade/i) }
91
+ end
92
+
93
+ context "without a name" do
94
+ let(:migration) do
95
+ <<~RUBY
96
+ drop_sequence
97
+ RUBY
98
+ end
99
+
100
+ it { is_expected.to fail_validation.because(/name can't be blank/i) }
101
+ end
102
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe ActiveRecord::Migration, "#rename_sequence" do
4
+ before_all { run_migration "create_schema :seq" }
5
+ before { run_migration(old_snippet) }
6
+
7
+ let(:old_snippet) do
8
+ <<~RUBY
9
+ create_sequence "global_num" do |s|
10
+ s.increment_by 2
11
+ s.min_value 0
12
+ s.max_value 2000
13
+ s.start_with 1
14
+ s.cache 10
15
+ s.cycle true
16
+ s.comment "Sequence for global numbers (odds then evens)"
17
+ end
18
+ RUBY
19
+ end
20
+
21
+ context "with a new name" do
22
+ let(:migration) do
23
+ <<~RUBY
24
+ rename_sequence "global_num", to: "seq.global_number"
25
+ RUBY
26
+ end
27
+ let(:new_snippet) do
28
+ <<~RUBY
29
+ create_sequence "seq.global_number" do |s|
30
+ s.increment_by 2
31
+ s.min_value 0
32
+ s.max_value 2000
33
+ s.start_with 1
34
+ s.cache 10
35
+ s.cycle true
36
+ s.comment "Sequence for global numbers (odds then evens)"
37
+ end
38
+ RUBY
39
+ end
40
+
41
+ its(:execution) { is_expected.to remove(old_snippet).from_schema }
42
+ its(:execution) { is_expected.to insert(new_snippet).into_schema }
43
+ its(:inversion) { is_expected.not_to change_schema }
44
+ end
45
+
46
+ context "when sequence was absent" do
47
+ let(:old_snippet) { "" }
48
+
49
+ context "without the `:if_exists` option" do
50
+ let(:migration) do
51
+ <<~RUBY
52
+ rename_sequence "global_num", to: "global_number"
53
+ RUBY
54
+ end
55
+
56
+ its(:execution) { is_expected.to raise_error(StandardError) }
57
+ end
58
+
59
+ context "with the `if_exists: true` option" do
60
+ let(:migration) do
61
+ <<~RUBY
62
+ rename_sequence "global_num", to: "global_number", if_exists: true
63
+ RUBY
64
+ end
65
+
66
+ its(:execution) { is_expected.not_to change_schema }
67
+ it { is_expected.to be_irreversible.because_of(/if_exists: true/i) }
68
+ end
69
+ end
70
+
71
+ context "with the same name" do
72
+ let(:migration) do
73
+ <<~RUBY
74
+ rename_sequence "global_num", to: "global_num"
75
+ RUBY
76
+ end
77
+
78
+ it { is_expected.to fail_validation.because(/new name must be different/i) }
79
+ end
80
+
81
+ context "without new name" do
82
+ let(:migration) do
83
+ <<~RUBY
84
+ rename_sequence "global_num"
85
+ RUBY
86
+ end
87
+
88
+ it { is_expected.to fail_validation.because(/new name can't be blank/i) }
89
+ end
90
+
91
+ context "without current name" do
92
+ let(:migration) do
93
+ <<~RUBY
94
+ rename_sequence to: "seq.global_number"
95
+ RUBY
96
+ end
97
+
98
+ it { is_expected.to fail_validation.because(/name can't be blank/i) }
99
+ end
100
+ end