data_migrate 8.1.1 → 11.3.0
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/Changelog.md +100 -0
- data/README.md +42 -8
- data/lib/data_migrate/config.rb +11 -1
- data/lib/data_migrate/{data_migrator_five.rb → data_migrator.rb} +15 -35
- data/lib/data_migrate/data_schema.rb +8 -8
- data/lib/data_migrate/data_schema_migration.rb +21 -5
- data/lib/data_migrate/database_configurations_wrapper.rb +11 -0
- data/lib/data_migrate/database_tasks.rb +233 -69
- data/lib/data_migrate/migration_context.rb +11 -8
- data/lib/data_migrate/rails_helper.rb +91 -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 +24 -43
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +8 -9
- data/lib/generators/data_migrate.rb +15 -2
- data/lib/generators/data_migration/data_migration_generator.rb +7 -2
- data/tasks/databases.rake +36 -121
- metadata +19 -77
- data/.github/workflows/gempush.yml +0 -29
- data/.gitignore +0 -11
- data/.hound.yml +0 -4
- data/.overcommit.yml +0 -21
- data/.rbenv-gemsets +0 -2
- data/.rspec +0 -3
- data/.rubocop.yml +0 -2
- data/.ruby-style.yml +0 -1061
- data/.ruby-version +0 -1
- data/.travis.yml +0 -14
- data/Appraisals +0 -15
- data/Gemfile +0 -4
- data/Gemfile.rails5.2 +0 -10
- data/Gemfile.rails6.1 +0 -11
- data/Rakefile +0 -2
- data/data_migrate.gemspec +0 -50
- data/gemfiles/rails_5.2.gemfile +0 -8
- data/gemfiles/rails_6.0.gemfile +0 -8
- data/gemfiles/rails_6.1.gemfile +0 -8
- data/gemfiles/rails_7.0.gemfile +0 -8
- data/lib/data_migrate/legacy_migrator.rb +0 -22
- data/lib/data_migrate/schema_migration_five.rb +0 -31
- data/screenshot.png +0 -0
- data/spec/data_migrate/config_spec.rb +0 -27
- data/spec/data_migrate/data_migrator_spec.rb +0 -101
- data/spec/data_migrate/data_schema_migration_spec.rb +0 -16
- data/spec/data_migrate/data_spec.rb +0 -85
- data/spec/data_migrate/database_tasks_spec.rb +0 -138
- data/spec/data_migrate/legacy_migrator_spec.rb +0 -50
- data/spec/data_migrate/migration.rb +0 -19
- data/spec/data_migrate/migration_context_spec.rb +0 -127
- data/spec/data_migrate/schema_dumper_spec.rb +0 -46
- data/spec/data_migrate/schema_migration_spec.rb +0 -99
- data/spec/data_migrate/status_service_spec.rb +0 -102
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +0 -164
- 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/20091231235959_some_name.rb +0 -9
- data/spec/db/data/20171231235959_super_update.rb +0 -9
- data/spec/db/data/20181128000207_excluded_file.rb.other_ext +0 -1
- data/spec/db/data/partial_schema/data_schema.rb +0 -1
- data/spec/db/data/partial_schema/test_data_schema.rb +0 -1
- data/spec/db/data/schema/data_schema.rb +0 -1
- data/spec/db/data/schema/test_data_schema.rb +0 -1
- 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 +0 -9
- data/spec/db/migrate/6.0/20202020202011_db_migration.rb +0 -9
- data/spec/generators/data_migration/data_migration_generator_spec.rb +0 -60
- data/spec/spec_helper.rb +0 -34
- data/tasks/.gitkeep +0 -0
@@ -1,127 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe DataMigrate::DataMigrator do
|
4
|
-
let(:context) {
|
5
|
-
if (Rails::VERSION::MAJOR == 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
|
-
|
28
|
-
let(:db_config) do
|
29
|
-
{
|
30
|
-
adapter: "sqlite3",
|
31
|
-
database: "spec/db/test.db"
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
describe :migrate do
|
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
|
-
|
46
|
-
it "migrates existing file" do
|
47
|
-
context.migrate(nil)
|
48
|
-
context.migrations_status
|
49
|
-
versions = DataMigrate::DataSchemaMigration.normalized_versions
|
50
|
-
expect(versions.count).to eq(2)
|
51
|
-
expect(versions).to include("20091231235959")
|
52
|
-
expect(versions).to include("20171231235959")
|
53
|
-
end
|
54
|
-
|
55
|
-
it "undo migration" do
|
56
|
-
context.migrate(nil)
|
57
|
-
context.run(:down, 20171231235959)
|
58
|
-
versions = DataMigrate::DataSchemaMigration.normalized_versions
|
59
|
-
expect(versions.count).to eq(1)
|
60
|
-
expect(versions).to include("20091231235959")
|
61
|
-
end
|
62
|
-
|
63
|
-
it "does not do anything if migration is undone twice" do
|
64
|
-
context.migrate(nil)
|
65
|
-
expect {
|
66
|
-
context.run(:down, 20171231235959)
|
67
|
-
}.to output(/Undoing SuperUpdate/).to_stdout
|
68
|
-
expect {
|
69
|
-
context.run(:down, 20171231235959)
|
70
|
-
}.not_to output(/Undoing SuperUpdate/).to_stdout
|
71
|
-
end
|
72
|
-
|
73
|
-
it "runs a specific migration" do
|
74
|
-
context.run(:up, 20171231235959)
|
75
|
-
versions = DataMigrate::DataSchemaMigration.normalized_versions
|
76
|
-
expect(versions.count).to eq(1)
|
77
|
-
expect(versions).to include("20171231235959")
|
78
|
-
end
|
79
|
-
|
80
|
-
it "does not do anything if migration is ran twice" do
|
81
|
-
expect {
|
82
|
-
context.run(:up, 20171231235959)
|
83
|
-
}.to output(/Doing SuperUpdate/).to_stdout
|
84
|
-
expect {
|
85
|
-
context.run(:down, 20171231235959)
|
86
|
-
}.not_to output(/Doing SuperUpdate/).to_stdout
|
87
|
-
end
|
88
|
-
|
89
|
-
it "alerts for an invalid specific migration" do
|
90
|
-
expect {
|
91
|
-
context.run(:up, 201712312)
|
92
|
-
}.to raise_error(
|
93
|
-
ActiveRecord::UnknownMigrationVersionError,
|
94
|
-
/No migration with version number 201712312/
|
95
|
-
)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "rolls back latest migration" do
|
99
|
-
context.migrate(nil)
|
100
|
-
expect {
|
101
|
-
context.rollback
|
102
|
-
}.to output(/Undoing SuperUpdate/).to_stdout
|
103
|
-
versions = DataMigrate::DataSchemaMigration.normalized_versions
|
104
|
-
expect(versions.count).to eq(1)
|
105
|
-
expect(versions).to include("20091231235959")
|
106
|
-
end
|
107
|
-
|
108
|
-
it "rolls back 2 migrations" do
|
109
|
-
context.migrate(nil)
|
110
|
-
schema_context.migrate(nil)
|
111
|
-
expect {
|
112
|
-
context.rollback(2)
|
113
|
-
}.to output(/Undoing SomeName/).to_stdout
|
114
|
-
versions = DataMigrate::DataSchemaMigration.normalized_versions
|
115
|
-
expect(versions.count).to eq(0)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "rolls back 2 migrations" do
|
119
|
-
context.migrate(nil)
|
120
|
-
expect {
|
121
|
-
context.rollback(2)
|
122
|
-
}.to output(/Undoing SomeName/).to_stdout
|
123
|
-
versions = DataMigrate::DataSchemaMigration.normalized_versions
|
124
|
-
expect(versions.count).to eq(0)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::SchemaDumper do
|
6
|
-
let(:subject) { DataMigrate::SchemaDumper }
|
7
|
-
let(:db_config) do
|
8
|
-
{
|
9
|
-
adapter: "sqlite3",
|
10
|
-
database: "spec/db/test.db"
|
11
|
-
}
|
12
|
-
end
|
13
|
-
let(:fixture_file_timestamps) do
|
14
|
-
%w[20091231235959 20101231235959 20111231235959]
|
15
|
-
end
|
16
|
-
|
17
|
-
describe :dump do
|
18
|
-
before do
|
19
|
-
allow(DataMigrate::DataMigrator).
|
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
|
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
|
31
|
-
|
32
|
-
after do
|
33
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
34
|
-
end
|
35
|
-
|
36
|
-
it "writes the define method with the version key to the stream" do
|
37
|
-
stream = StringIO.new
|
38
|
-
DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
39
|
-
stream.rewind
|
40
|
-
|
41
|
-
last_version = fixture_file_timestamps.last
|
42
|
-
expected = "DataMigrate::Data.define(version: #{last_version})"
|
43
|
-
expect(stream.read).to include expected
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
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
|
-
let(:subject) { DataMigrate::SchemaMigration }
|
15
|
-
let(:db_config) do
|
16
|
-
{
|
17
|
-
adapter: "sqlite3",
|
18
|
-
database: "spec/db/test.db"
|
19
|
-
}
|
20
|
-
end
|
21
|
-
let(:fixture_file_timestamps) do
|
22
|
-
%w[20091231235959 20101231235959 20111231235959]
|
23
|
-
end
|
24
|
-
|
25
|
-
before do
|
26
|
-
ActiveRecord::Base.establish_connection(db_config)
|
27
|
-
ActiveRecord::SchemaMigration.create_table
|
28
|
-
end
|
29
|
-
|
30
|
-
after do
|
31
|
-
ActiveRecord::Migration.drop_table("schema_migrations")
|
32
|
-
end
|
33
|
-
|
34
|
-
describe :pending_schema_migrations do
|
35
|
-
it "list sorted schema migrations" do
|
36
|
-
expect(subject).to receive(:migrations_paths) {
|
37
|
-
migration_path
|
38
|
-
}
|
39
|
-
migrations = subject.pending_schema_migrations
|
40
|
-
|
41
|
-
expect(migrations.count).to eq 2
|
42
|
-
expect(migrations[0][:version]).to eq(20131111111111)
|
43
|
-
expect(migrations[1][:version]).to eq(20202020202011)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe :run do
|
48
|
-
it do
|
49
|
-
expect {
|
50
|
-
subject.run(:up, migration_path, 20202020202011)
|
51
|
-
}.to output(/20202020202011 DbMigration: migrating/).to_stdout
|
52
|
-
versions = ActiveRecord::SchemaMigration.normalized_versions
|
53
|
-
expect(versions.first).to eq("20202020202011")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "undo migration" do
|
57
|
-
subject.run(:up, migration_path, 20202020202011)
|
58
|
-
expect {
|
59
|
-
subject.run(:down, migration_path, 20202020202011)
|
60
|
-
}.to output(/Undoing DbMigration/).to_stdout
|
61
|
-
versions = ActiveRecord::SchemaMigration.normalized_versions
|
62
|
-
expect(versions.count).to eq(0)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
if Rails.version > '6'
|
67
|
-
describe :migrations_paths do
|
68
|
-
context 'when a db_name is configured' do
|
69
|
-
let(:config) { double(:config) }
|
70
|
-
let(:paths) { ['spec/db/migrate/6.0', 'spec/db/components/migrate/6.0'] }
|
71
|
-
let(:config_options) do
|
72
|
-
if Rails.version > '6.1'
|
73
|
-
{ env_name: 'test', name: 'primary' }
|
74
|
-
else
|
75
|
-
{ env_name: 'test', spec_name: 'primary' }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
before do
|
80
|
-
DataMigrate.configure do |config|
|
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)
|
88
|
-
|
89
|
-
allow(config).to receive(:migrations_paths).and_return(paths)
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'lists schema migration paths' do
|
93
|
-
expect(subject.migrations_paths.size).to eq(2)
|
94
|
-
expect(subject.migrations_paths).to eq(paths)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe DataMigrate::StatusService do
|
5
|
-
let(:subject) { DataMigrate::SchemaDumper }
|
6
|
-
let(:db_config) do
|
7
|
-
{
|
8
|
-
adapter: "sqlite3",
|
9
|
-
database: "spec/db/test.db"
|
10
|
-
}
|
11
|
-
end
|
12
|
-
let(:service) { DataMigrate::StatusService }
|
13
|
-
|
14
|
-
context "table does not exists" do
|
15
|
-
before do
|
16
|
-
ActiveRecord::Base.establish_connection(db_config)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "show error message" do
|
20
|
-
allow_any_instance_of(service).to receive(:table_name) { "bogus"}
|
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
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "table exists" do
|
32
|
-
let(:fixture_file_timestamps) do
|
33
|
-
%w[20091231235959 20101231235959 20111231235959]
|
34
|
-
end
|
35
|
-
|
36
|
-
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
|
-
ActiveRecord::SchemaMigration.create_table
|
42
|
-
DataMigrate::DataMigrator.assure_data_schema_table
|
43
|
-
|
44
|
-
ActiveRecord::Base.connection.execute <<-SQL
|
45
|
-
INSERT INTO #{DataMigrate::DataSchemaMigration.table_name}
|
46
|
-
VALUES #{fixture_file_timestamps.map { |t| "(#{t})" }.join(', ')}
|
47
|
-
SQL
|
48
|
-
|
49
|
-
allow_any_instance_of(service).to receive(:root_folder) { "./" }
|
50
|
-
end
|
51
|
-
|
52
|
-
after do
|
53
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "shows successfully executed migration" do
|
57
|
-
stream = StringIO.new
|
58
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
59
|
-
stream.rewind
|
60
|
-
|
61
|
-
expected = " up 20091231235959 Some name"
|
62
|
-
expect(stream.read).to include expected
|
63
|
-
end
|
64
|
-
|
65
|
-
it "excludes files without .rb extension" do
|
66
|
-
stream = StringIO.new
|
67
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
68
|
-
stream.rewind
|
69
|
-
|
70
|
-
expected = "20181128000207 Excluded file"
|
71
|
-
expect(stream.read).to_not include expected
|
72
|
-
end
|
73
|
-
|
74
|
-
it "shows missing file migration" do
|
75
|
-
stream = StringIO.new
|
76
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
77
|
-
stream.rewind
|
78
|
-
|
79
|
-
expected = " up 20101231235959 ********** NO FILE **********"
|
80
|
-
s = stream.read
|
81
|
-
expect(s).to include expected
|
82
|
-
end
|
83
|
-
|
84
|
-
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
|
-
expected = " down 20171231235959 Super update"
|
90
|
-
s = stream.read
|
91
|
-
expect(s).to include expected
|
92
|
-
end
|
93
|
-
|
94
|
-
it "outputs migrations in chronological order" do
|
95
|
-
stream = StringIO.new
|
96
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
97
|
-
stream.rewind
|
98
|
-
s = stream.read
|
99
|
-
expect(s.index("20091231235959")).to be < s.index("20111231235959")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::Tasks::DataMigrateTasks do
|
6
|
-
describe :dump do
|
7
|
-
let(:db_config) do
|
8
|
-
{
|
9
|
-
adapter: "sqlite3",
|
10
|
-
database: "spec/db/other_test.db"
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
14
|
-
before do
|
15
|
-
allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
|
16
|
-
allow(DataMigrate::DatabaseTasks).to receive(:db_dir).and_return("spec/db")
|
17
|
-
end
|
18
|
-
|
19
|
-
after do
|
20
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when not given a separate db config' do
|
24
|
-
it 'does not override the default connection' do
|
25
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
26
|
-
expect(ActiveRecord::Base).not_to receive(:establish_connection)
|
27
|
-
expect(DataMigrate::SchemaDumper).to receive(:dump)
|
28
|
-
DataMigrate::Tasks::DataMigrateTasks.dump
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when given ' do
|
33
|
-
let(:override_config) do
|
34
|
-
{
|
35
|
-
'host' => '127.0.0.1',
|
36
|
-
'database' => 'other_test',
|
37
|
-
'adapter' => 'sqlite3',
|
38
|
-
'username' => 'root',
|
39
|
-
'password' => nil,
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
before do
|
44
|
-
DataMigrate.configure do |config|
|
45
|
-
config.db_configuration = override_config
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'overrides the default connection' do
|
50
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
51
|
-
expect(ActiveRecord::Base).to receive(:establish_connection).with(override_config)
|
52
|
-
DataMigrate::Tasks::DataMigrateTasks.dump
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe :migrate do
|
58
|
-
let(:db_config) do
|
59
|
-
{
|
60
|
-
adapter: "sqlite3",
|
61
|
-
database: "spec/db/test.db"
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
before do
|
66
|
-
allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
|
67
|
-
ActiveRecord::Base.establish_connection(db_config)
|
68
|
-
end
|
69
|
-
|
70
|
-
after do
|
71
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
72
|
-
end
|
73
|
-
|
74
|
-
it do
|
75
|
-
expect {
|
76
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
77
|
-
}.to output(/20091231235959 SomeName: migrating/).to_stdout
|
78
|
-
end
|
79
|
-
|
80
|
-
it do
|
81
|
-
expect {
|
82
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
83
|
-
}.to output(/20171231235959 SuperUpdate: migrating/).to_stdout
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe :abort_if_pending_migrations do
|
88
|
-
subject { DataMigrate::Tasks::DataMigrateTasks.abort_if_pending_migrations(migrations, message) }
|
89
|
-
|
90
|
-
let(:message) { "ABORT_MESSAGE" }
|
91
|
-
|
92
|
-
context "when there are no pending migrations" do
|
93
|
-
let(:migrations) { [] }
|
94
|
-
|
95
|
-
it "shouldn't do anything" do
|
96
|
-
expect { subject }.to_not raise_error
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "when there are pending migrations" do
|
101
|
-
let(:migrations) do
|
102
|
-
[{
|
103
|
-
name: "A",
|
104
|
-
version: 1
|
105
|
-
}, {
|
106
|
-
name: 'B',
|
107
|
-
version: 2
|
108
|
-
}]
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should abort with given message and print names and versions of pending migrations" do
|
112
|
-
expect { subject }
|
113
|
-
.to raise_error(SystemExit, message)
|
114
|
-
.and output("You have 2 pending migrations:\n 1 A\n 2 B\n").to_stdout
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe :status do
|
120
|
-
let(:db_config) do
|
121
|
-
{
|
122
|
-
adapter: "sqlite3",
|
123
|
-
database: "spec/db/test.db"
|
124
|
-
}
|
125
|
-
end
|
126
|
-
|
127
|
-
before do
|
128
|
-
if Rails::VERSION::MAJOR == 5
|
129
|
-
ActiveRecord::Base.configurations['test'] = db_config
|
130
|
-
else
|
131
|
-
hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', db_config)
|
132
|
-
config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
|
133
|
-
allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
|
134
|
-
end
|
135
|
-
|
136
|
-
allow(Rails).to receive(:root) { '.' }
|
137
|
-
|
138
|
-
if Rails::VERSION::MAJOR == 5
|
139
|
-
allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:schema_migrations_path) { 'spec/db/migrate/5.2' }
|
140
|
-
else
|
141
|
-
allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:schema_migrations_path) { 'spec/db/migrate/6.0' }
|
142
|
-
end
|
143
|
-
|
144
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
145
|
-
end
|
146
|
-
|
147
|
-
after do
|
148
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should display data migration status" do
|
152
|
-
expect {
|
153
|
-
DataMigrate::Tasks::DataMigrateTasks.status
|
154
|
-
}.to output(/up 20091231235959 Some name/).to_stdout
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should display schema and data migration status" do
|
158
|
-
expect {
|
159
|
-
DataMigrate::Tasks::DataMigrateTasks.status_with_schema
|
160
|
-
}.to output(match(/up data 20091231235959 Some name/)
|
161
|
-
.and match(/down schema 20131111111111 Late migration/)).to_stdout
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
# This file should be excluded
|
@@ -1 +0,0 @@
|
|
1
|
-
DataMigrate::Data.define(version: 20091231235959)
|
@@ -1 +0,0 @@
|
|
1
|
-
DataMigrate::Data.define(version: 20091231235959)
|
@@ -1 +0,0 @@
|
|
1
|
-
DataMigrate::Data.define(version: 20171231235959)
|
@@ -1 +0,0 @@
|
|
1
|
-
DataMigrate::Data.define(version: 20171231235959)
|
@@ -1 +0,0 @@
|
|
1
|
-
# This file should be excluded
|