data_migrate 9.0.0 → 10.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/gempush.yml +1 -0
- data/.travis.yml +0 -3
- data/Appraisals +0 -4
- data/Changelog.md +8 -0
- data/README.md +3 -3
- data/lib/data_migrate/{data_migrator_five.rb → data_migrator.rb} +0 -11
- data/lib/data_migrate/database_tasks.rb +12 -72
- data/lib/data_migrate/{schema_migration_six.rb → schema_migration.rb} +4 -2
- data/lib/data_migrate/{status_service_five.rb → status_service.rb} +12 -6
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +19 -39
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +3 -8
- data/spec/data_migrate/config_spec.rb +13 -10
- data/spec/data_migrate/data_migrator_spec.rb +11 -32
- data/spec/data_migrate/data_spec.rb +0 -11
- data/spec/data_migrate/database_tasks_spec.rb +10 -58
- data/spec/data_migrate/legacy_migrator_spec.rb +6 -18
- data/spec/data_migrate/migration.rb +11 -13
- data/spec/data_migrate/migration_context_spec.rb +11 -37
- data/spec/data_migrate/schema_dumper_spec.rb +10 -23
- data/spec/data_migrate/schema_migration_spec.rb +40 -42
- data/spec/data_migrate/status_service_spec.rb +26 -55
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +37 -71
- data/spec/db/data/20091231235959_some_name.rb +1 -1
- data/spec/db/data/20171231235959_super_update.rb +1 -1
- data/spec/spec_helper.rb +2 -8
- data/tasks/databases.rake +28 -5
- metadata +9 -19
- data/Gemfile.rails5.2 +0 -10
- data/gemfiles/rails_5.2.gemfile +0 -8
- data/lib/data_migrate/schema_migration_five.rb +0 -31
- data/spec/db/6.0/20091231235959_some_name.rb +0 -9
- data/spec/db/6.0/20171231235959_super_update.rb +0 -9
- data/spec/db/data-6.0/20091231235959_some_name.rb +0 -9
- data/spec/db/data-6.0/20171231235959_super_update.rb +0 -9
- data/spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext +0 -1
- data/spec/db/migrate/5.2/20131111111111_late_migration.rb +0 -9
- data/spec/db/migrate/5.2/20202020202011_db_migration.rb +0 -9
- /data/spec/db/migrate/{6.0/20131111111111_late_migration.rb → 20131111111111_late_migration.rb} +0 -0
- /data/spec/db/migrate/{6.0/20202020202011_db_migration.rb → 20202020202011_db_migration.rb} +0 -0
@@ -4,13 +4,7 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
describe DataMigrate::DatabaseTasks do
|
6
6
|
let(:subject) { DataMigrate::DatabaseTasks }
|
7
|
-
let(:migration_path) {
|
8
|
-
if Rails::VERSION::MAJOR == 5
|
9
|
-
"spec/db/migrate/5.2"
|
10
|
-
else
|
11
|
-
"spec/db/migrate/6.0"
|
12
|
-
end
|
13
|
-
}
|
7
|
+
let(:migration_path) { "spec/db/migrate" }
|
14
8
|
let(:data_migrations_path) {
|
15
9
|
DataMigrate.config.data_migrations_path
|
16
10
|
}
|
@@ -33,9 +27,8 @@ describe DataMigrate::DatabaseTasks do
|
|
33
27
|
allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) {
|
34
28
|
data_migrations_path
|
35
29
|
}
|
36
|
-
allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
|
37
30
|
ActiveRecord::Base.establish_connection(db_config)
|
38
|
-
if
|
31
|
+
if Gem::Dependency.new("rails", ">= 6.1").match?("rails", Gem.loaded_specs["rails"].version)
|
39
32
|
hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', db_config)
|
40
33
|
config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
|
41
34
|
allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
|
@@ -44,19 +37,10 @@ describe DataMigrate::DatabaseTasks do
|
|
44
37
|
end
|
45
38
|
end
|
46
39
|
|
47
|
-
describe :schema_file do
|
48
|
-
it "returns the correct data schema file path" do
|
49
|
-
expect(subject.schema_file(nil)).to eq "db/data_schema.rb"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
40
|
context "migrations" do
|
54
41
|
after do
|
55
|
-
|
56
|
-
|
57
|
-
rescue ActiveRecord::StatementInvalid
|
58
|
-
end
|
59
|
-
ActiveRecord::Migration.drop_table("schema_migrations")
|
42
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
43
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
60
44
|
end
|
61
45
|
|
62
46
|
before do
|
@@ -68,51 +52,19 @@ describe DataMigrate::DatabaseTasks do
|
|
68
52
|
allow(DataMigrate::DatabaseTasks).to receive(:data_migrations_path) {
|
69
53
|
data_migrations_path
|
70
54
|
}.at_least(:once)
|
71
|
-
allow(DataMigrate::DatabaseTasks).to receive(:schema_migrations_path) {
|
72
|
-
migration_path
|
73
|
-
}.at_least(:once)
|
74
55
|
end
|
75
56
|
|
76
57
|
describe :past_migrations do
|
77
|
-
it do
|
58
|
+
it "returns past migration records" do
|
78
59
|
subject.forward
|
79
|
-
|
80
|
-
expect(
|
81
|
-
expect(
|
60
|
+
migrations = subject.past_migrations
|
61
|
+
expect(migrations.count).to eq 1
|
62
|
+
expect(migrations.first[:version]).to eq 20091231235959
|
82
63
|
end
|
83
64
|
|
84
65
|
it "shows nothing without any migrations" do
|
85
|
-
|
86
|
-
expect(
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe :load_schema_current do
|
91
|
-
before do
|
92
|
-
allow(DataMigrate::DataMigrator).to receive(:full_migrations_path).and_return(migration_path)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "loads the current schema file" do
|
96
|
-
if Rails::VERSION::MAJOR < 6
|
97
|
-
skip("Not implemented for Rails lower than 6")
|
98
|
-
end
|
99
|
-
allow(subject).to receive(:schema_location).and_return("spec/db/data/schema/")
|
100
|
-
|
101
|
-
subject.load_schema_current
|
102
|
-
versions = DataMigrate::DataSchemaMigration.normalized_versions
|
103
|
-
expect(versions.count).to eq(2)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "loads schema file that has not been update with latest data migrations" do
|
107
|
-
if Rails::VERSION::MAJOR < 6
|
108
|
-
skip("Not implemented for Rails lower than 6")
|
109
|
-
end
|
110
|
-
|
111
|
-
allow(subject).to receive(:schema_location).and_return("spec/db/data/partial_schema/")
|
112
|
-
|
113
|
-
subject.load_schema_current
|
114
|
-
versions = DataMigrate::DataSchemaMigration.normalized_versions
|
115
|
-
expect(versions.count).to eq(1)
|
66
|
+
migrations = subject.past_migrations
|
67
|
+
expect(migrations.count).to eq 0
|
116
68
|
end
|
117
69
|
end
|
118
70
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe DataMigrate::LegacyMigrator do
|
@@ -5,30 +7,17 @@ describe DataMigrate::LegacyMigrator do
|
|
5
7
|
DataMigrate::MigrationContext.new("spec/db/data")
|
6
8
|
}
|
7
9
|
|
8
|
-
after do
|
9
|
-
begin
|
10
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
11
|
-
ActiveRecord::Migration.drop_table("schema_migrations")
|
12
|
-
rescue StandardError
|
13
|
-
nil
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
10
|
before do
|
18
|
-
ActiveRecord::Base.establish_connection(db_config)
|
19
11
|
ActiveRecord::SchemaMigration.create_table
|
20
12
|
DataMigrate::DataSchemaMigration.create_table
|
21
13
|
end
|
22
14
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
database: "spec/db/test.db"
|
27
|
-
}
|
15
|
+
after do
|
16
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
17
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
28
18
|
end
|
29
19
|
|
30
20
|
it "migrate legacy migrations to be in correct table" do
|
31
|
-
DataMigrate::DataSchemaMigration.create_table
|
32
21
|
# simulate creation of legacy data migration when
|
33
22
|
# it was recorded in schema table
|
34
23
|
ActiveRecord::SchemaMigration.create(version: "20091231235959")
|
@@ -36,7 +25,7 @@ describe DataMigrate::LegacyMigrator do
|
|
36
25
|
# create one migration in correct place
|
37
26
|
DataMigrate::DataSchemaMigration.create(version: "20171231235959")
|
38
27
|
|
39
|
-
migrated = DataMigrate::DataMigrator
|
28
|
+
migrated = DataMigrate::DataMigrator.new(:up, []).load_migrated
|
40
29
|
expect(migrated.count).to eq 1
|
41
30
|
|
42
31
|
DataMigrate::LegacyMigrator.new("spec/db/data").migrate
|
@@ -46,5 +35,4 @@ describe DataMigrate::LegacyMigrator do
|
|
46
35
|
migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
|
47
36
|
expect(migrated.count).to eq 2
|
48
37
|
end
|
49
|
-
|
50
38
|
end
|
@@ -1,19 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
subject = DataMigrate::MigrationFive
|
5
|
-
else
|
6
|
-
subject = DataMigrate::Migration
|
7
|
-
end
|
3
|
+
require 'spec_helper'
|
8
4
|
|
9
|
-
describe
|
10
|
-
|
11
|
-
|
5
|
+
describe DataMigrate::Migration do
|
6
|
+
describe ".table_name" do
|
7
|
+
it "returns correct table name" do
|
8
|
+
expect(subject.table_name).to eq("data_migrations")
|
9
|
+
end
|
12
10
|
end
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
describe ".index_name" do
|
13
|
+
it "returns correct primary key name" do
|
14
|
+
expect(subject.primary_key).to eq("version")
|
15
|
+
end
|
18
16
|
end
|
19
17
|
end
|
@@ -1,48 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe DataMigrate::DataMigrator do
|
4
|
-
let(:context) {
|
5
|
-
|
6
|
-
DataMigrate::MigrationContext.new("spec/db/data")
|
7
|
-
else
|
8
|
-
DataMigrate::MigrationContext.new("spec/db/data-6.0")
|
9
|
-
end
|
10
|
-
}
|
11
|
-
let(:schema_context) {
|
12
|
-
if (Rails::VERSION::MAJOR == 5)
|
13
|
-
ActiveRecord::MigrationContext.new("spec/db/migrate/5.2")
|
14
|
-
else
|
15
|
-
ActiveRecord::MigrationContext.new("spec/db/migrate/6.0", ActiveRecord::Base.connection.schema_migration)
|
16
|
-
end
|
17
|
-
}
|
6
|
+
let(:context) { DataMigrate::MigrationContext.new("spec/db/data") }
|
7
|
+
let(:schema_context) { ActiveRecord::MigrationContext.new("spec/db/migrate", ActiveRecord::Base.connection.schema_migration) }
|
18
8
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
ActiveRecord::Migration.drop_table("schema_migrations")
|
23
|
-
rescue StandardError
|
24
|
-
nil
|
25
|
-
end
|
9
|
+
before do
|
10
|
+
ActiveRecord::SchemaMigration.create_table
|
11
|
+
DataMigrate::DataSchemaMigration.create_table
|
26
12
|
end
|
27
13
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
database: "spec/db/test.db"
|
32
|
-
}
|
14
|
+
after do
|
15
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
16
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
33
17
|
end
|
34
18
|
|
35
|
-
describe
|
36
|
-
before do
|
37
|
-
ActiveRecord::Base.establish_connection(db_config)
|
38
|
-
ActiveRecord::SchemaMigration.create_table
|
39
|
-
end
|
40
|
-
|
41
|
-
after do
|
42
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
43
|
-
ActiveRecord::Migration.drop_table("schema_migrations")
|
44
|
-
end
|
45
|
-
|
19
|
+
describe "migrate" do
|
46
20
|
it "migrates existing file" do
|
47
21
|
context.migrate(nil)
|
48
22
|
context.migrations_status
|
@@ -4,35 +4,22 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
describe DataMigrate::SchemaDumper do
|
6
6
|
let(:subject) { DataMigrate::SchemaDumper }
|
7
|
-
let(:db_config) do
|
8
|
-
{
|
9
|
-
adapter: "sqlite3",
|
10
|
-
database: "spec/db/test.db"
|
11
|
-
}
|
12
|
-
end
|
13
7
|
let(:fixture_file_timestamps) do
|
14
8
|
%w[20091231235959 20101231235959 20111231235959]
|
15
9
|
end
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
ActiveRecord::SchemaMigration.create_table
|
24
|
-
DataMigrate::DataMigrator.assure_data_schema_table
|
25
|
-
|
26
|
-
ActiveRecord::Base.connection.execute <<-SQL
|
27
|
-
INSERT INTO #{DataMigrate::DataSchemaMigration.table_name}
|
28
|
-
VALUES #{fixture_file_timestamps.map { |t| "(#{t})" }.join(', ')}
|
29
|
-
SQL
|
30
|
-
end
|
11
|
+
before do
|
12
|
+
ActiveRecord::SchemaMigration.create_table
|
13
|
+
DataMigrate::DataSchemaMigration.create_table
|
14
|
+
DataMigrate::DataSchemaMigration.create(fixture_file_timestamps.map { |t| { version: t } })
|
15
|
+
end
|
31
16
|
|
32
|
-
|
33
|
-
|
34
|
-
|
17
|
+
after do
|
18
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
19
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
20
|
+
end
|
35
21
|
|
22
|
+
describe ".dump" do
|
36
23
|
it "writes the define method with the version key to the stream" do
|
37
24
|
stream = StringIO.new
|
38
25
|
DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
@@ -3,32 +3,20 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe DataMigrate::SchemaMigration do
|
6
|
-
let(:migration_path) {
|
7
|
-
if Rails::VERSION::MAJOR == 5
|
8
|
-
"spec/db/migrate/5.2"
|
9
|
-
else
|
10
|
-
"spec/db/migrate/6.0"
|
11
|
-
end
|
12
|
-
}
|
13
|
-
|
14
6
|
let(:subject) { DataMigrate::SchemaMigration }
|
15
|
-
let(:
|
16
|
-
{
|
17
|
-
adapter: "sqlite3",
|
18
|
-
database: "spec/db/test.db"
|
19
|
-
}
|
20
|
-
end
|
7
|
+
let(:migration_path) { "spec/db/migrate" }
|
21
8
|
let(:fixture_file_timestamps) do
|
22
9
|
%w[20091231235959 20101231235959 20111231235959]
|
23
10
|
end
|
24
11
|
|
25
12
|
before do
|
26
|
-
ActiveRecord::Base.establish_connection(db_config)
|
27
13
|
ActiveRecord::SchemaMigration.create_table
|
14
|
+
DataMigrate::DataSchemaMigration.create_table
|
28
15
|
end
|
29
16
|
|
30
17
|
after do
|
31
|
-
ActiveRecord::Migration.drop_table("
|
18
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
19
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
32
20
|
end
|
33
21
|
|
34
22
|
describe :pending_schema_migrations do
|
@@ -36,6 +24,7 @@ describe DataMigrate::SchemaMigration do
|
|
36
24
|
expect(subject).to receive(:migrations_paths) {
|
37
25
|
migration_path
|
38
26
|
}
|
27
|
+
|
39
28
|
migrations = subject.pending_schema_migrations
|
40
29
|
|
41
30
|
expect(migrations.count).to eq 2
|
@@ -45,7 +34,7 @@ describe DataMigrate::SchemaMigration do
|
|
45
34
|
end
|
46
35
|
|
47
36
|
describe :run do
|
48
|
-
it do
|
37
|
+
it "can run up task" do
|
49
38
|
expect {
|
50
39
|
subject.run(:up, migration_path, 20202020202011)
|
51
40
|
}.to output(/20202020202011 DbMigration: migrating/).to_stdout
|
@@ -53,47 +42,56 @@ describe DataMigrate::SchemaMigration do
|
|
53
42
|
expect(versions.first).to eq("20202020202011")
|
54
43
|
end
|
55
44
|
|
56
|
-
it "
|
45
|
+
it "can run down task" do
|
57
46
|
subject.run(:up, migration_path, 20202020202011)
|
47
|
+
|
58
48
|
expect {
|
59
49
|
subject.run(:down, migration_path, 20202020202011)
|
60
50
|
}.to output(/Undoing DbMigration/).to_stdout
|
51
|
+
|
61
52
|
versions = ActiveRecord::SchemaMigration.normalized_versions
|
53
|
+
|
62
54
|
expect(versions.count).to eq(0)
|
63
55
|
end
|
64
56
|
end
|
65
57
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
58
|
+
describe :migrations_paths do
|
59
|
+
context 'when a db_name is configured' do
|
60
|
+
let(:config) { double(:config) }
|
61
|
+
let(:paths) { ['spec/db/migrate', 'spec/db/migrate/other'] }
|
62
|
+
let(:specification_name) { "primary" }
|
63
|
+
let(:config_options) do
|
64
|
+
if Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
|
65
|
+
{ env_name: Rails.env, spec_name: specification_name }
|
66
|
+
elsif Gem::Dependency.new("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
|
67
|
+
{ env_name: Rails.env, name: specification_name }
|
77
68
|
end
|
69
|
+
end
|
78
70
|
|
79
|
-
|
80
|
-
|
81
|
-
config.spec_name = 'primary'
|
82
|
-
end
|
83
|
-
|
84
|
-
allow(ActiveRecord::Base.configurations)
|
85
|
-
.to receive(:configs_for)
|
86
|
-
.with(config_options)
|
87
|
-
.and_return(config)
|
71
|
+
before do
|
72
|
+
@original_config_spec_name = DataMigrate.config.spec_name
|
88
73
|
|
89
|
-
|
74
|
+
DataMigrate.configure do |config|
|
75
|
+
config.spec_name = specification_name
|
90
76
|
end
|
91
77
|
|
92
|
-
|
93
|
-
|
94
|
-
|
78
|
+
allow(ActiveRecord::Base.configurations)
|
79
|
+
.to receive(:configs_for)
|
80
|
+
.with(config_options)
|
81
|
+
.and_return(config)
|
82
|
+
allow(config).to receive(:migrations_paths).and_return(paths)
|
83
|
+
end
|
84
|
+
|
85
|
+
after do
|
86
|
+
DataMigrate.configure do |config|
|
87
|
+
config.spec_name = @original_config_spec_name
|
95
88
|
end
|
96
89
|
end
|
90
|
+
|
91
|
+
it 'lists schema migration paths' do
|
92
|
+
expect(subject.migrations_paths.size).to eq(paths.count)
|
93
|
+
expect(subject.migrations_paths).to eq(paths)
|
94
|
+
end
|
97
95
|
end
|
98
96
|
end
|
99
97
|
end
|
@@ -1,30 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "spec_helper"
|
3
4
|
|
4
5
|
describe DataMigrate::StatusService do
|
5
|
-
let(:subject) { DataMigrate::
|
6
|
-
let(:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
let(:subject) { DataMigrate::StatusService }
|
7
|
+
let(:stream) { StringIO.new }
|
8
|
+
let(:stream_data) { stream.read }
|
9
|
+
let(:connection_db_config) do
|
10
|
+
if Gem::Dependency.new("rails", ">= 6.1").match?("rails", Gem.loaded_specs["rails"].version)
|
11
|
+
ActiveRecord::Base.connection_db_config
|
12
|
+
else
|
13
|
+
ActiveRecord::Base.configurations.configs_for.first
|
14
|
+
end
|
11
15
|
end
|
12
|
-
let(:service) { DataMigrate::StatusService }
|
13
16
|
|
14
17
|
context "table does not exists" do
|
15
18
|
before do
|
16
|
-
|
19
|
+
allow_any_instance_of(subject).to receive(:table_name) { "bogus"}
|
20
|
+
|
21
|
+
subject.dump(connection_db_config, stream)
|
22
|
+
stream.rewind
|
17
23
|
end
|
18
24
|
|
19
25
|
it "show error message" do
|
20
|
-
|
21
|
-
stream = StringIO.new
|
22
|
-
|
23
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
24
|
-
|
25
|
-
stream.rewind
|
26
|
-
expected = "Data migrations table does not exist"
|
27
|
-
expect(stream.read).to include expected
|
26
|
+
expect(stream_data).to include("Data migrations table does not exist")
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
@@ -34,69 +33,41 @@ describe DataMigrate::StatusService do
|
|
34
33
|
end
|
35
34
|
|
36
35
|
before do
|
37
|
-
allow(DataMigrate::DataMigrator).
|
38
|
-
to receive(:db_config) { db_config }.at_least(:once)
|
39
|
-
ActiveRecord::Base.establish_connection(db_config)
|
40
|
-
|
41
36
|
ActiveRecord::SchemaMigration.create_table
|
42
|
-
DataMigrate::
|
37
|
+
DataMigrate::DataSchemaMigration.create_table
|
38
|
+
DataMigrate::DataSchemaMigration.create(fixture_file_timestamps.map { |t| { version: t } })
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
VALUES #{fixture_file_timestamps.map { |t| "(#{t})" }.join(', ')}
|
47
|
-
SQL
|
48
|
-
|
49
|
-
allow_any_instance_of(service).to receive(:root_folder) { "./" }
|
40
|
+
subject.dump(connection_db_config, stream)
|
41
|
+
stream.rewind
|
50
42
|
end
|
51
43
|
|
52
44
|
after do
|
53
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
45
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
46
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
54
47
|
end
|
55
48
|
|
56
49
|
it "shows successfully executed migration" do
|
57
|
-
stream = StringIO.new
|
58
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
59
|
-
stream.rewind
|
60
|
-
|
61
50
|
expected = " up 20091231235959 Some name"
|
62
|
-
expect(
|
51
|
+
expect(stream_data).to include expected
|
63
52
|
end
|
64
53
|
|
65
54
|
it "excludes files without .rb extension" do
|
66
|
-
stream = StringIO.new
|
67
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
68
|
-
stream.rewind
|
69
|
-
|
70
55
|
expected = "20181128000207 Excluded file"
|
71
|
-
expect(
|
56
|
+
expect(stream_data).to_not include expected
|
72
57
|
end
|
73
58
|
|
74
59
|
it "shows missing file migration" do
|
75
|
-
stream = StringIO.new
|
76
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
77
|
-
stream.rewind
|
78
|
-
|
79
60
|
expected = " up 20101231235959 ********** NO FILE **********"
|
80
|
-
|
81
|
-
expect(s).to include expected
|
61
|
+
expect(stream_data).to include expected
|
82
62
|
end
|
83
63
|
|
84
64
|
it "shows migration that has not run yet" do
|
85
|
-
stream = StringIO.new
|
86
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
87
|
-
stream.rewind
|
88
|
-
|
89
65
|
expected = " down 20171231235959 Super update"
|
90
|
-
|
91
|
-
expect(s).to include expected
|
66
|
+
expect(stream_data).to include expected
|
92
67
|
end
|
93
68
|
|
94
69
|
it "outputs migrations in chronological order" do
|
95
|
-
|
96
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
97
|
-
stream.rewind
|
98
|
-
s = stream.read
|
99
|
-
expect(s.index("20091231235959")).to be < s.index("20111231235959")
|
70
|
+
expect(stream_data.index("20091231235959")).to be < stream_data.index("20111231235959")
|
100
71
|
end
|
101
72
|
end
|
102
73
|
end
|