|
1 | 1 | require 'spec_helper' |
2 | 2 | require 'migrations/helpers/migration_shared_context' |
3 | 3 |
|
4 | | -RSpec.describe 'migration to add service_binding_k8s_enabled column to apps table', isolation: :truncation, type: :migration do |
| 4 | +RSpec.describe 'migration to add file-based service binding feature columns to apps table', isolation: :truncation, type: :migration do |
5 | 5 | include_context 'migration' do |
6 | 6 | let(:migration_filename) { '20250225132929_add_apps_file_based_service_binding_feature_columns.rb' } |
7 | 7 | end |
|
44 | 44 | expect { run_migration }.not_to raise_error |
45 | 45 | expect(db[:apps].columns).to include(:service_binding_k8s_enabled) |
46 | 46 | expect(db[:apps].columns).to include(:file_based_vcap_services_enabled) |
47 | | - expect(check_constraint_exists?(db)).to be(true) |
| 47 | + expect(check_constraint_exists?(db)).to be(true) if check_constraint_supported?(db) |
48 | 48 | end |
49 | 49 | end |
50 | 50 | end |
|
83 | 83 | expect { run_migration }.not_to raise_error |
84 | 84 | expect(db[:apps].columns).to include(:service_binding_k8s_enabled) |
85 | 85 | expect(db[:apps].columns).to include(:file_based_vcap_services_enabled) |
86 | | - expect(check_constraint_exists?(db)).to be(true) |
| 86 | + expect(check_constraint_exists?(db)).to be(true) if check_constraint_supported?(db) |
87 | 87 | end |
88 | 88 | end |
89 | 89 | end |
90 | 90 |
|
91 | 91 | describe 'check constraint' do |
92 | | - it 'adds the check constraint' do |
93 | | - expect(check_constraint_exists?(db)).to be(false) |
94 | | - run_migration |
95 | | - expect(check_constraint_exists?(db)).to be(true) |
96 | | - end |
| 92 | + context 'when supported' do |
| 93 | + before do |
| 94 | + skip 'check constraint not supported by db' unless check_constraint_supported?(db) |
| 95 | + end |
97 | 96 |
|
98 | | - it 'forbids setting both features to true' do |
99 | | - run_migration |
100 | | - expect { db[:apps].insert(guid: 'some_app', file_based_vcap_services_enabled: true, service_binding_k8s_enabled: true) }.to(raise_error do |error| |
101 | | - expect(error.inspect).to include('only_one_sb_feature_enabled', 'violate') |
102 | | - end) |
103 | | - end |
| 97 | + it 'adds the check constraint' do |
| 98 | + expect(check_constraint_exists?(db)).to be(false) |
| 99 | + run_migration |
| 100 | + expect(check_constraint_exists?(db)).to be(true) |
| 101 | + end |
104 | 102 |
|
105 | | - context 'when it already exists' do |
106 | | - before do |
107 | | - db.add_column :apps, :service_binding_k8s_enabled, :boolean, default: false, null: false, if_not_exists: true |
108 | | - db.add_column :apps, :file_based_vcap_services_enabled, :boolean, default: false, null: false, if_not_exists: true |
109 | | - db.alter_table :apps do |
110 | | - add_constraint(name: :only_one_sb_feature_enabled) do |
111 | | - Sequel.lit('NOT (service_binding_k8s_enabled AND file_based_vcap_services_enabled)') |
| 103 | + it 'forbids setting both features to true' do |
| 104 | + run_migration |
| 105 | + expect { db[:apps].insert(guid: 'some_app', file_based_vcap_services_enabled: true, service_binding_k8s_enabled: true) }.to(raise_error do |error| |
| 106 | + expect(error.inspect).to include('only_one_sb_feature_enabled', 'violate') |
| 107 | + end) |
| 108 | + end |
| 109 | + |
| 110 | + context 'when it already exists' do |
| 111 | + before do |
| 112 | + db.add_column :apps, :service_binding_k8s_enabled, :boolean, default: false, null: false, if_not_exists: true |
| 113 | + db.add_column :apps, :file_based_vcap_services_enabled, :boolean, default: false, null: false, if_not_exists: true |
| 114 | + db.alter_table :apps do |
| 115 | + add_constraint(name: :only_one_sb_feature_enabled) do |
| 116 | + Sequel.lit('NOT (service_binding_k8s_enabled AND file_based_vcap_services_enabled)') |
| 117 | + end |
112 | 118 | end |
113 | 119 | end |
| 120 | + |
| 121 | + it 'does not fail' do |
| 122 | + expect { run_migration }.not_to raise_error |
| 123 | + end |
| 124 | + end |
| 125 | + end |
| 126 | + |
| 127 | + context 'when not supported' do |
| 128 | + before do |
| 129 | + skip 'check constraint supported by db' if check_constraint_supported?(db) |
114 | 130 | end |
115 | 131 |
|
116 | 132 | it 'does not fail' do |
117 | 133 | expect { run_migration }.not_to raise_error |
| 134 | + expect(db[:apps].columns).to include(:service_binding_k8s_enabled) |
| 135 | + expect(db[:apps].columns).to include(:file_based_vcap_services_enabled) |
118 | 136 | end |
119 | 137 | end |
120 | 138 | end |
|
178 | 196 | end |
179 | 197 |
|
180 | 198 | describe 'check constraint' do |
181 | | - it 'removes the check constraint' do |
182 | | - expect(check_constraint_exists?(db)).to be(true) |
183 | | - run_rollback |
184 | | - expect(check_constraint_exists?(db)).to be(false) |
| 199 | + context 'when supported' do |
| 200 | + before do |
| 201 | + skip 'check constraint not supported by db' unless check_constraint_supported?(db) |
| 202 | + end |
| 203 | + |
| 204 | + it 'removes the check constraint' do |
| 205 | + expect(check_constraint_exists?(db)).to be(true) |
| 206 | + run_rollback |
| 207 | + expect(check_constraint_exists?(db)).to be(false) |
| 208 | + end |
| 209 | + |
| 210 | + context 'when it does not exist' do |
| 211 | + before do |
| 212 | + db.alter_table :apps do |
| 213 | + drop_constraint :only_one_sb_feature_enabled |
| 214 | + end |
| 215 | + end |
| 216 | + |
| 217 | + it 'does not fail' do |
| 218 | + expect(check_constraint_exists?(db)).to be(false) |
| 219 | + expect { run_rollback }.not_to raise_error |
| 220 | + expect(db[:apps].columns).not_to include(:service_binding_k8s_enabled) |
| 221 | + expect(db[:apps].columns).not_to include(:file_based_vcap_services_enabled) |
| 222 | + expect(check_constraint_exists?(db)).to be(false) |
| 223 | + end |
| 224 | + end |
185 | 225 | end |
186 | 226 |
|
187 | | - context 'when it does not exist' do |
| 227 | + context 'when not supported' do |
188 | 228 | before do |
189 | | - db.alter_table :apps do |
190 | | - drop_constraint :only_one_sb_feature_enabled |
191 | | - end |
| 229 | + skip 'check constraint supported by db' if check_constraint_supported?(db) |
192 | 230 | end |
193 | 231 |
|
194 | 232 | it 'does not fail' do |
195 | | - expect(check_constraint_exists?(db)).to be(false) |
196 | 233 | expect { run_rollback }.not_to raise_error |
197 | 234 | expect(db[:apps].columns).not_to include(:service_binding_k8s_enabled) |
198 | 235 | expect(db[:apps].columns).not_to include(:file_based_vcap_services_enabled) |
199 | | - expect(check_constraint_exists?(db)).to be(false) |
200 | 236 | end |
201 | 237 | end |
202 | 238 | end |
|
0 commit comments