|
| 1 | +require 'migrations/helpers/migration_shared_context' |
| 2 | + |
| 3 | +RSpec.shared_context 'bigint migration step1' do |
| 4 | + subject(:run_migration) { Sequel::Migrator.run(db, migrations_path, target: current_migration_index, allow_missing_migration_files: true) } |
| 5 | + |
| 6 | + include_context 'migration' |
| 7 | + |
| 8 | + it 'works' do |
| 9 | + run_migration |
| 10 | + expect(true).to be_truthy |
| 11 | + end |
| 12 | + |
| 13 | + # let(:skip_bigint_id_migration) { nil } |
| 14 | + # |
| 15 | + # before do |
| 16 | + # # allow_any_instance_of(VCAP::CloudController::Config).to receive(:get).and_call_original |
| 17 | + # # allow_any_instance_of(VCAP::CloudController::Config).to receive(:get).with(:skip_bigint_id_migration).and_return(skip_bigint_id_migration) |
| 18 | + # end |
| 19 | + # |
| 20 | + # describe 'up' do |
| 21 | + # context 'when skip_bigint_id_migration is false' do |
| 22 | + # let(:skip_bigint_id_migration) { false } |
| 23 | + # |
| 24 | + # context 'when the table is empty' do |
| 25 | + # before do |
| 26 | + # db[table].delete |
| 27 | + # end |
| 28 | + # |
| 29 | + # it "changes the id column's type to bigint" do |
| 30 | + # expect(db).to have_table_with_column_and_type(table, :id, 'integer') |
| 31 | + # |
| 32 | + # run_migration |
| 33 | + # |
| 34 | + # expect(db).to have_table_with_column_and_type(table, :id, 'bigint') |
| 35 | + # end |
| 36 | + # |
| 37 | + # it 'does not add the id_bigint column' do |
| 38 | + # expect(db).not_to have_table_with_column(table, :id_bigint) |
| 39 | + # |
| 40 | + # run_migration |
| 41 | + # |
| 42 | + # expect(db).not_to have_table_with_column(table, :id_bigint) |
| 43 | + # end |
| 44 | + # end |
| 45 | + # |
| 46 | + # context 'when the table is not empty' do |
| 47 | + # before do |
| 48 | + # db[table].insert(insert_hash) |
| 49 | + # end |
| 50 | + # |
| 51 | + # it "does not change the id column's type" do |
| 52 | + # expect(db).to have_table_with_column_and_type(table, :id, 'integer') |
| 53 | + # |
| 54 | + # run_migration |
| 55 | + # |
| 56 | + # expect(db).to have_table_with_column_and_type(table, :id, 'integer') |
| 57 | + # end |
| 58 | + # |
| 59 | + # it 'adds the id_bigint column' do |
| 60 | + # expect(db).not_to have_table_with_column(table, :id_bigint) |
| 61 | + # |
| 62 | + # run_migration |
| 63 | + # |
| 64 | + # expect(db).to have_table_with_column_and_type(table, :id_bigint, 'bigint') |
| 65 | + # end |
| 66 | + # end |
| 67 | + # end |
| 68 | + # |
| 69 | + # context 'when skip_bigint_id_migration is true' do |
| 70 | + # let(:skip_bigint_id_migration) { true } |
| 71 | + # |
| 72 | + # it "neither changes the id column's type, nor adds the id_bigint column" do |
| 73 | + # # expect(db).to have_table_with_column_and_type(table, :id, 'integer') |
| 74 | + # # expect(db).not_to have_table_with_column(table, :id_bigint) |
| 75 | + # # |
| 76 | + # # run_migration |
| 77 | + # # |
| 78 | + # # expect(db).to have_table_with_column_and_type(table, :id, 'integer') |
| 79 | + # # expect(db).not_to have_table_with_column(table, :id_bigint) |
| 80 | + # end |
| 81 | + # end |
| 82 | + # end |
| 83 | + # |
| 84 | + # describe 'down' do |
| 85 | + # subject(:run_rollback) { Sequel::Migrator.run(db, migrations_path, target: current_migration_index - 1, allow_missing_migration_files: true) } |
| 86 | + # |
| 87 | + # context 'when the table is empty' do |
| 88 | + # before do |
| 89 | + # db[table].delete |
| 90 | + # run_migration |
| 91 | + # end |
| 92 | + # |
| 93 | + # it "reverts the id column's type to integer" do |
| 94 | + # expect(db).to have_table_with_column_and_type(table, :id, 'bigint') |
| 95 | + # |
| 96 | + # run_rollback |
| 97 | + # |
| 98 | + # expect(db).to have_table_with_column_and_type(table, :id, 'integer') |
| 99 | + # end |
| 100 | + # end |
| 101 | + # |
| 102 | + # context 'when the table is not empty' do |
| 103 | + # before do |
| 104 | + # db[table].insert(insert_hash) |
| 105 | + # run_migration |
| 106 | + # end |
| 107 | + # |
| 108 | + # it 'drops the id_bigint column' do |
| 109 | + # expect(db).to have_table_with_column(table, :id_bigint) |
| 110 | + # |
| 111 | + # run_rollback |
| 112 | + # |
| 113 | + # expect(db).not_to have_table_with_column(table, :id_bigint) |
| 114 | + # end |
| 115 | + # end |
| 116 | + # end |
| 117 | +end |
0 commit comments