|
| 1 | +require 'spec_helper' |
| 2 | +require 'migrations/helpers/migration_shared_context' |
| 3 | + |
| 4 | +RSpec.describe 'migration to make lifecycle_type non-nullable on apps, droplets, and builds', isolation: :truncation, type: :migration do |
| 5 | + include_context 'migration' do |
| 6 | + let(:migration_filename) { '20260825120100_make_lifecycle_type_non_nullable.rb' } |
| 7 | + end |
| 8 | + |
| 9 | + before do |
| 10 | + db[:apps].insert(guid: 'app-guid', lifecycle_type: 'buildpack') |
| 11 | + db[:droplets].insert(guid: 'droplet-guid', state: 'STAGED', lifecycle_type: 'buildpack') |
| 12 | + db[:builds].insert(guid: 'build-guid', lifecycle_type: 'buildpack') |
| 13 | + end |
| 14 | + |
| 15 | + it 'makes lifecycle_type non-nullable, is reversible, and is idempotent' do |
| 16 | + Sequel::Migrator.run(db, migrations_path, target: current_migration_index, allow_missing_migration_files: true) |
| 17 | + |
| 18 | + expect(db.schema(:apps).find { |col| col[0] == :lifecycle_type }[1][:allow_null]).to be false |
| 19 | + expect(db.schema(:droplets).find { |col| col[0] == :lifecycle_type }[1][:allow_null]).to be false |
| 20 | + expect(db.schema(:builds).find { |col| col[0] == :lifecycle_type }[1][:allow_null]).to be false |
| 21 | + |
| 22 | + expect { Sequel::Migrator.run(db, migrations_path, target: current_migration_index, allow_missing_migration_files: true) }.not_to raise_error |
| 23 | + |
| 24 | + Sequel::Migrator.run(db, migrations_path, target: current_migration_index - 1, allow_missing_migration_files: true) |
| 25 | + |
| 26 | + expect(db.schema(:apps).find { |col| col[0] == :lifecycle_type }[1][:allow_null]).to be true |
| 27 | + expect(db.schema(:droplets).find { |col| col[0] == :lifecycle_type }[1][:allow_null]).to be true |
| 28 | + expect(db.schema(:builds).find { |col| col[0] == :lifecycle_type }[1][:allow_null]).to be true |
| 29 | + end |
| 30 | +end |
0 commit comments