File: legacy_migrator_spec.rb

package info (click to toggle)
ruby-data-migrate 6.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 568 kB
  • sloc: ruby: 1,844; makefile: 6
file content (50 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require "spec_helper"

describe DataMigrate::LegacyMigrator do
  let(:context) {
    DataMigrate::MigrationContext.new("spec/db/data")
  }

  after do
    begin
      ActiveRecord::Migration.drop_table("data_migrations")
      ActiveRecord::Migration.drop_table("schema_migrations")
    rescue StandardError
      nil
    end
  end

  before do
    ActiveRecord::Base.establish_connection(db_config)
    ActiveRecord::SchemaMigration.create_table
    DataMigrate::DataSchemaMigration.create_table
  end

  let(:db_config) do
    {
      adapter: "sqlite3",
      database: "spec/db/test.db"
    }
  end

  it "migrate legacy migrations to be in correct table" do
    DataMigrate::DataSchemaMigration.create_table
    # simulate creation of legacy data migration when
    # it was recorded in schema table
    ActiveRecord::SchemaMigration.create(version: "20091231235959")

    # create one migration in correct place
    DataMigrate::DataSchemaMigration.create(version: "20171231235959")

    migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
    expect(migrated.count).to eq 1

    DataMigrate::LegacyMigrator.new("spec/db/data").migrate

    # after migacy migrator has been run, we should have records
    # of both migrations
    migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
    expect(migrated.count).to eq 2
  end

end