data_migrate 8.5.0 → 9.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +34 -0
- data/.github/workflows/gempush.yml +6 -7
- data/.gitignore +3 -2
- data/Appraisals +5 -9
- data/Changelog.md +44 -0
- data/Gemfile.lock +148 -0
- data/README.md +9 -7
- data/data_migrate.gemspec +1 -10
- data/gemfiles/rails_6.1.gemfile +1 -1
- data/gemfiles/rails_6.1.gemfile.lock +227 -0
- data/gemfiles/rails_7.0.gemfile.lock +229 -0
- data/gemfiles/{rails_6.0.gemfile → rails_7.1.gemfile} +1 -1
- data/gemfiles/rails_7.1.gemfile.lock +262 -0
- data/lib/data_migrate/config.rb +1 -1
- data/lib/data_migrate/{data_migrator_five.rb → data_migrator.rb} +11 -34
- data/lib/data_migrate/data_schema.rb +2 -2
- data/lib/data_migrate/data_schema_migration.rb +24 -7
- data/lib/data_migrate/database_tasks.rb +37 -74
- data/lib/data_migrate/migration_context.rb +11 -8
- data/lib/data_migrate/rails_helper.rb +79 -0
- data/lib/data_migrate/schema_dumper.rb +1 -1
- data/lib/data_migrate/{schema_migration_six.rb → schema_migration.rb} +7 -4
- data/lib/data_migrate/{status_service_five.rb → status_service.rb} +14 -8
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +16 -37
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +4 -9
- data/spec/data_migrate/config_spec.rb +13 -10
- data/spec/data_migrate/data_migrator_spec.rb +25 -43
- data/spec/data_migrate/data_schema_migration_spec.rb +25 -8
- data/spec/data_migrate/data_spec.rb +1 -12
- data/spec/data_migrate/database_tasks_spec.rb +43 -76
- data/spec/data_migrate/migration.rb +11 -13
- data/spec/data_migrate/migration_context_spec.rb +20 -39
- data/spec/data_migrate/schema_dumper_spec.rb +11 -21
- data/spec/data_migrate/schema_migration_spec.rb +46 -41
- data/spec/data_migrate/status_service_spec.rb +29 -55
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +32 -67
- data/spec/db/data/20091231235959_some_name.rb +1 -1
- data/spec/db/data/20171231235959_super_update.rb +1 -1
- data/spec/db/migrate/{5.2/20131111111111_late_migration.rb → 20131111111111_late_migration.rb} +1 -1
- data/spec/db/migrate/{6.0/20202020202011_db_migration.rb → 20202020202011_db_migration.rb} +1 -1
- data/spec/spec_helper.rb +2 -8
- data/tasks/databases.rake +15 -13
- metadata +20 -34
- data/.ruby-version +0 -1
- data/.travis.yml +0 -14
- data/Gemfile.rails5.2 +0 -10
- data/gemfiles/rails_5.2.gemfile +0 -8
- data/lib/data_migrate/legacy_migrator.rb +0 -22
- data/lib/data_migrate/schema_migration_five.rb +0 -31
- data/spec/data_migrate/legacy_migrator_spec.rb +0 -50
- 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/20202020202011_db_migration.rb +0 -9
- data/spec/db/migrate/6.0/20131111111111_late_migration.rb +0 -9
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe DataMigrate::DataMigrator do
|
4
|
-
let(:
|
6
|
+
let(:described_class) { DataMigrate::DataMigrator }
|
7
|
+
|
5
8
|
let(:db_config) do
|
6
9
|
{
|
7
10
|
adapter: "sqlite3",
|
@@ -10,49 +13,35 @@ describe DataMigrate::DataMigrator do
|
|
10
13
|
end
|
11
14
|
|
12
15
|
before do
|
13
|
-
allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
|
14
16
|
ActiveRecord::Base.establish_connection(db_config)
|
17
|
+
DataMigrate::RailsHelper.schema_migration.create_table
|
18
|
+
DataMigrate::RailsHelper.data_schema_migration.create_table
|
15
19
|
end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
::ActiveRecord::SchemaMigration.create_table
|
22
|
-
DataMigrate::DataSchemaMigration.create_table
|
23
|
-
end
|
21
|
+
after do
|
22
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
23
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
ActiveRecord::Migration.drop_table("schema_migrations")
|
28
|
-
end
|
26
|
+
describe ".load_migrated" do
|
27
|
+
let(:migrator) { DataMigrate::RailsHelper.data_migrator(:up, []) }
|
29
28
|
|
30
|
-
it do
|
31
|
-
|
32
|
-
DataMigrate::
|
33
|
-
::
|
34
|
-
DataMigrate::
|
35
|
-
|
36
|
-
migrated = subject.new(:up, []).load_migrated
|
29
|
+
it "loads migrated versions" do
|
30
|
+
DataMigrate::RailsHelper.data_schema_migration.create_version(20090000000000)
|
31
|
+
DataMigrate::RailsHelper.schema_create_version(20100000000000)
|
32
|
+
DataMigrate::RailsHelper.data_schema_migration.create_version(20110000000000)
|
33
|
+
DataMigrate::RailsHelper.schema_create_version(20120000000000)
|
34
|
+
migrated = migrator.load_migrated
|
37
35
|
expect(migrated.count).to eq 2
|
38
36
|
expect(migrated).to include 20090000000000
|
39
37
|
expect(migrated).to include 20110000000000
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
43
|
-
describe :
|
44
|
-
|
45
|
-
allow(subject).to receive(:db_config) { db_config }.at_least(:once)
|
46
|
-
ActiveRecord::Base.establish_connection(db_config)
|
47
|
-
end
|
48
|
-
|
49
|
-
after do
|
50
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
51
|
-
end
|
52
|
-
|
53
|
-
it do
|
41
|
+
describe :create_data_schema_table do
|
42
|
+
it "creates the data_migrations table" do
|
54
43
|
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
55
|
-
|
44
|
+
described_class.create_data_schema_table
|
56
45
|
expect(
|
57
46
|
ActiveRecord::Base.connection.table_exists?("data_migrations")
|
58
47
|
).to eq true
|
@@ -60,15 +49,8 @@ describe DataMigrate::DataMigrator do
|
|
60
49
|
end
|
61
50
|
|
62
51
|
describe "#migrations_status" do
|
63
|
-
before do
|
64
|
-
allow(subject).to receive(:db_config) { db_config }.at_least(:once)
|
65
|
-
ActiveRecord::Base.establish_connection(db_config)
|
66
|
-
::ActiveRecord::SchemaMigration.create_table
|
67
|
-
DataMigrate::DataSchemaMigration.create_table
|
68
|
-
end
|
69
|
-
|
70
52
|
it "returns all migrations statuses" do
|
71
|
-
status =
|
53
|
+
status = described_class.migrations_status
|
72
54
|
expect(status.length).to eq 2
|
73
55
|
expect(status.first).to eq ["down", "20091231235959", "Some name"]
|
74
56
|
expect(status.second).to eq ["down", "20171231235959", "Super update"]
|
@@ -78,19 +60,19 @@ describe DataMigrate::DataMigrator do
|
|
78
60
|
describe :match do
|
79
61
|
context "when the file does not match" do
|
80
62
|
it "returns nil" do
|
81
|
-
expect(
|
63
|
+
expect(described_class.match("not_a_data_migration_file")).to be_nil
|
82
64
|
end
|
83
65
|
end
|
84
66
|
|
85
67
|
context "when the file doesn't end in .rb" do
|
86
68
|
it "returns nil" do
|
87
|
-
expect(
|
69
|
+
expect(described_class.match("20091231235959_some_name.rb.un~")).to be_nil
|
88
70
|
end
|
89
71
|
end
|
90
72
|
|
91
73
|
context "when the file matches" do
|
92
74
|
it "returns a valid MatchData object" do
|
93
|
-
match_data =
|
75
|
+
match_data = described_class.match("20091231235959_some_name.rb")
|
94
76
|
|
95
77
|
expect(match_data[0]).to eq "20091231235959_some_name.rb"
|
96
78
|
expect(match_data[1]).to eq "20091231235959"
|
@@ -1,16 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DataMigrate::DataSchemaMigration do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_1
|
5
|
+
let(:connection) { double(:connection) }
|
6
|
+
let(:subject) { DataMigrate::DataSchemaMigration.new(connection) }
|
7
|
+
|
8
|
+
describe :table_name do
|
9
|
+
it "returns correct table name" do
|
10
|
+
expect(subject.table_name).to eq("data_migrations")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe :index_name do
|
15
|
+
it "returns correct primary key name" do
|
16
|
+
expect(subject.primary_key).to eq("version")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
else
|
20
|
+
let(:subject) { DataMigrate::DataSchemaMigration }
|
21
|
+
describe :table_name do
|
22
|
+
it "returns correct table name" do
|
23
|
+
expect(subject.table_name).to eq("data_migrations")
|
24
|
+
end
|
8
25
|
end
|
9
|
-
end
|
10
26
|
|
11
|
-
|
12
|
-
|
13
|
-
|
27
|
+
describe :index_name do
|
28
|
+
it "returns correct primary key name" do
|
29
|
+
expect(subject.primary_key).to eq("version")
|
30
|
+
end
|
14
31
|
end
|
15
32
|
end
|
16
33
|
end
|
@@ -4,12 +4,6 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
describe DataMigrate::Data do
|
6
6
|
let(:subject) { DataMigrate::Data }
|
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
|
@@ -28,11 +22,6 @@ describe DataMigrate::Data do
|
|
28
22
|
end
|
29
23
|
|
30
24
|
describe :define do
|
31
|
-
before do
|
32
|
-
allow(DataMigrate::DataMigrator).
|
33
|
-
to receive(:db_config) { db_config }
|
34
|
-
end
|
35
|
-
|
36
25
|
after do
|
37
26
|
ActiveRecord::Migration.drop_table("data_migrations")
|
38
27
|
end
|
@@ -66,7 +55,7 @@ describe DataMigrate::Data do
|
|
66
55
|
|
67
56
|
sql_select = <<-SQL
|
68
57
|
SELECT version
|
69
|
-
FROM #{DataMigrate::
|
58
|
+
FROM #{DataMigrate::RailsHelper.data_schema_migration.table_name}
|
70
59
|
SQL
|
71
60
|
|
72
61
|
db_list_data = ActiveRecord::Base.connection.
|
@@ -4,22 +4,10 @@ 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
|
}
|
17
|
-
let(:db_config) do
|
18
|
-
{
|
19
|
-
adapter: "sqlite3",
|
20
|
-
database: "spec/db/test.db"
|
21
|
-
}
|
22
|
-
end
|
23
11
|
|
24
12
|
before do
|
25
13
|
# In a normal Rails installation, db_dir would defer to
|
@@ -33,34 +21,20 @@ describe DataMigrate::DatabaseTasks do
|
|
33
21
|
allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) {
|
34
22
|
data_migrations_path
|
35
23
|
}
|
36
|
-
|
37
|
-
ActiveRecord::
|
38
|
-
|
39
|
-
|
40
|
-
config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
|
41
|
-
allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
|
42
|
-
else
|
43
|
-
ActiveRecord::Base.configurations[:test] = db_config
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
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
|
24
|
+
ActiveRecord::Base.establish_connection({ adapter: "sqlite3", database: "spec/db/test.db" })
|
25
|
+
hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', { adapter: "sqlite3", database: "spec/db/test.db" })
|
26
|
+
config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
|
27
|
+
allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
|
51
28
|
end
|
52
29
|
|
53
30
|
context "migrations" do
|
54
31
|
after do
|
55
|
-
|
56
|
-
|
57
|
-
rescue ActiveRecord::StatementInvalid
|
58
|
-
end
|
59
|
-
ActiveRecord::Migration.drop_table("schema_migrations")
|
32
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
33
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
60
34
|
end
|
61
35
|
|
62
36
|
before do
|
63
|
-
|
37
|
+
DataMigrate::RailsHelper.schema_migration.create_table
|
64
38
|
|
65
39
|
allow(DataMigrate::SchemaMigration).to receive(:migrations_paths) {
|
66
40
|
migration_path
|
@@ -68,71 +42,64 @@ describe DataMigrate::DatabaseTasks do
|
|
68
42
|
allow(DataMigrate::DatabaseTasks).to receive(:data_migrations_path) {
|
69
43
|
data_migrations_path
|
70
44
|
}.at_least(:once)
|
71
|
-
allow(DataMigrate::DatabaseTasks).to receive(:schema_migrations_path) {
|
72
|
-
migration_path
|
73
|
-
}.at_least(:once)
|
74
45
|
end
|
75
46
|
|
76
47
|
describe :past_migrations do
|
77
|
-
it do
|
48
|
+
it "returns past migration records" do
|
78
49
|
subject.forward
|
79
|
-
|
80
|
-
expect(
|
81
|
-
expect(
|
50
|
+
migrations = subject.past_migrations
|
51
|
+
expect(migrations.count).to eq 1
|
52
|
+
expect(migrations.first[:version]).to eq 20091231235959
|
82
53
|
end
|
83
54
|
|
84
55
|
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)
|
56
|
+
migrations = subject.past_migrations
|
57
|
+
expect(migrations.count).to eq 0
|
116
58
|
end
|
117
59
|
end
|
118
60
|
|
119
61
|
describe :forward do
|
120
|
-
|
121
62
|
it "run forward default amount of times" do
|
122
63
|
subject.forward
|
123
|
-
versions = DataMigrate::
|
64
|
+
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
124
65
|
expect(versions.count).to eq(1)
|
125
66
|
end
|
126
67
|
|
127
68
|
it "run forward defined number of times" do
|
128
69
|
subject.forward(2)
|
129
|
-
versions = DataMigrate::
|
70
|
+
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
130
71
|
expect(versions.count).to eq(1)
|
131
72
|
expect(versions.first).to eq "20091231235959"
|
132
|
-
versions =
|
73
|
+
versions = DataMigrate::RailsHelper.schema_migration.normalized_versions
|
133
74
|
expect(versions.count).to eq(1)
|
134
75
|
expect(versions.first).to eq "20131111111111"
|
135
76
|
end
|
136
77
|
end
|
78
|
+
|
79
|
+
if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_0
|
80
|
+
describe :schema_dump_path do
|
81
|
+
before do
|
82
|
+
allow(ActiveRecord::Base).to receive(:configurations).and_return(ActiveRecord::DatabaseConfigurations.new([db_config]))
|
83
|
+
end
|
84
|
+
|
85
|
+
context "for primary database" do
|
86
|
+
let(:db_config) { ActiveRecord::DatabaseConfigurations::HashConfig.new("development", "primary", {} ) }
|
87
|
+
|
88
|
+
context "for :ruby db format" do
|
89
|
+
it 'returns the data schema path' do
|
90
|
+
allow(ActiveRecord).to receive(:schema_format).and_return(:ruby)
|
91
|
+
expect(subject.schema_dump_path(db_config)).to eq("db/data_schema.rb")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "for :sql db format" do
|
96
|
+
it 'returns the data schema path' do
|
97
|
+
allow(ActiveRecord).to receive(:schema_format).and_return(:sql)
|
98
|
+
expect(subject.schema_dump_path(db_config, :sql)).to eq("db/data_schema.rb")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
137
104
|
end
|
138
105
|
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,30 +1,10 @@
|
|
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
|
-
}
|
18
|
-
|
19
|
-
after do
|
20
|
-
begin
|
21
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
22
|
-
ActiveRecord::Migration.drop_table("schema_migrations")
|
23
|
-
rescue StandardError
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
6
|
+
let(:context) { DataMigrate::MigrationContext.new("spec/db/data") }
|
7
|
+
let(:schema_context) { ActiveRecord::MigrationContext.new("spec/db/migrate", ActiveRecord::Base.connection.schema_migration) }
|
28
8
|
let(:db_config) do
|
29
9
|
{
|
30
10
|
adapter: "sqlite3",
|
@@ -32,21 +12,22 @@ describe DataMigrate::DataMigrator do
|
|
32
12
|
}
|
33
13
|
end
|
34
14
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
15
|
+
before do
|
16
|
+
ActiveRecord::Base.establish_connection(db_config)
|
17
|
+
DataMigrate::RailsHelper.schema_migration.create_table
|
18
|
+
DataMigrate::RailsHelper.data_schema_migration.create_table
|
19
|
+
end
|
40
20
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
21
|
+
after do
|
22
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
23
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
24
|
+
end
|
45
25
|
|
26
|
+
describe "migrate" do
|
46
27
|
it "migrates existing file" do
|
47
28
|
context.migrate(nil)
|
48
29
|
context.migrations_status
|
49
|
-
versions = DataMigrate::
|
30
|
+
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
50
31
|
expect(versions.count).to eq(2)
|
51
32
|
expect(versions).to include("20091231235959")
|
52
33
|
expect(versions).to include("20171231235959")
|
@@ -55,7 +36,7 @@ describe DataMigrate::DataMigrator do
|
|
55
36
|
it "undo migration" do
|
56
37
|
context.migrate(nil)
|
57
38
|
context.run(:down, 20171231235959)
|
58
|
-
versions = DataMigrate::
|
39
|
+
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
59
40
|
expect(versions.count).to eq(1)
|
60
41
|
expect(versions).to include("20091231235959")
|
61
42
|
end
|
@@ -72,7 +53,7 @@ describe DataMigrate::DataMigrator do
|
|
72
53
|
|
73
54
|
it "runs a specific migration" do
|
74
55
|
context.run(:up, 20171231235959)
|
75
|
-
versions = DataMigrate::
|
56
|
+
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
76
57
|
expect(versions.count).to eq(1)
|
77
58
|
expect(versions).to include("20171231235959")
|
78
59
|
end
|
@@ -100,7 +81,7 @@ describe DataMigrate::DataMigrator do
|
|
100
81
|
expect {
|
101
82
|
context.rollback
|
102
83
|
}.to output(/Undoing SuperUpdate/).to_stdout
|
103
|
-
versions = DataMigrate::
|
84
|
+
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
104
85
|
expect(versions.count).to eq(1)
|
105
86
|
expect(versions).to include("20091231235959")
|
106
87
|
end
|
@@ -111,7 +92,7 @@ describe DataMigrate::DataMigrator do
|
|
111
92
|
expect {
|
112
93
|
context.rollback(2)
|
113
94
|
}.to output(/Undoing SomeName/).to_stdout
|
114
|
-
versions = DataMigrate::
|
95
|
+
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
115
96
|
expect(versions.count).to eq(0)
|
116
97
|
end
|
117
98
|
|
@@ -120,7 +101,7 @@ describe DataMigrate::DataMigrator do
|
|
120
101
|
expect {
|
121
102
|
context.rollback(2)
|
122
103
|
}.to output(/Undoing SomeName/).to_stdout
|
123
|
-
versions = DataMigrate::
|
104
|
+
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
124
105
|
expect(versions.count).to eq(0)
|
125
106
|
end
|
126
107
|
end
|
@@ -4,35 +4,25 @@ 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
|
-
to receive(:db_config) { db_config }.at_least(:once)
|
21
|
-
ActiveRecord::Base.establish_connection(db_config)
|
22
|
-
|
23
|
-
ActiveRecord::SchemaMigration.create_table
|
24
|
-
DataMigrate::DataMigrator.assure_data_schema_table
|
11
|
+
before do
|
12
|
+
DataMigrate::RailsHelper.schema_migration.create_table
|
13
|
+
DataMigrate::RailsHelper.data_schema_migration.create_table
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
VALUES #{fixture_file_timestamps.map { |t| "(#{t})" }.join(', ')}
|
29
|
-
SQL
|
15
|
+
fixture_file_timestamps.map do |t|
|
16
|
+
DataMigrate::RailsHelper.data_schema_migration.create_version(t)
|
30
17
|
end
|
18
|
+
end
|
31
19
|
|
32
|
-
|
33
|
-
|
34
|
-
|
20
|
+
after do
|
21
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
22
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
23
|
+
end
|
35
24
|
|
25
|
+
describe ".dump" do
|
36
26
|
it "writes the define method with the version key to the stream" do
|
37
27
|
stream = StringIO.new
|
38
28
|
DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|