data_migrate 9.2.0 → 11.2.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 +36 -0
- data/README.md +20 -13
- data/lib/data_migrate/data_migrator.rb +5 -1
- data/lib/data_migrate/data_schema.rb +6 -6
- data/lib/data_migrate/database_configurations_wrapper.rb +11 -0
- data/lib/data_migrate/database_tasks.rb +218 -58
- data/lib/data_migrate/rails_helper.rb +15 -3
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +8 -6
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +1 -0
- data/lib/generators/data_migration/data_migration_generator.rb +2 -1
- data/tasks/databases.rake +9 -46
- metadata +8 -52
- data/.github/workflows/build.yml +0 -34
- data/.github/workflows/gempush.yml +0 -28
- data/.gitignore +0 -12
- 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/Appraisals +0 -11
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -148
- data/Gemfile.rails6.1 +0 -11
- data/Rakefile +0 -2
- data/data_migrate.gemspec +0 -41
- data/gemfiles/rails_6.1.gemfile +0 -8
- data/gemfiles/rails_6.1.gemfile.lock +0 -227
- data/gemfiles/rails_7.0.gemfile +0 -8
- data/gemfiles/rails_7.0.gemfile.lock +0 -229
- data/gemfiles/rails_7.1.gemfile +0 -8
- data/gemfiles/rails_7.1.gemfile.lock +0 -262
- data/screenshot.png +0 -0
- data/spec/data_migrate/config_spec.rb +0 -69
- data/spec/data_migrate/data_migrator_spec.rb +0 -83
- data/spec/data_migrate/data_schema_migration_spec.rb +0 -33
- data/spec/data_migrate/data_spec.rb +0 -74
- data/spec/data_migrate/database_tasks_spec.rb +0 -105
- data/spec/data_migrate/migration.rb +0 -17
- data/spec/data_migrate/migration_context_spec.rb +0 -108
- data/spec/data_migrate/schema_dumper_spec.rb +0 -36
- data/spec/data_migrate/schema_migration_spec.rb +0 -104
- data/spec/data_migrate/status_service_spec.rb +0 -76
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +0 -129
- 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/migrate/20131111111111_late_migration.rb +0 -9
- data/spec/db/migrate/20202020202011_db_migration.rb +0 -9
- data/spec/generators/data_migration/data_migration_generator_spec.rb +0 -101
- data/spec/spec_helper.rb +0 -28
- data/tasks/.gitkeep +0 -0
@@ -1,108 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::DataMigrator do
|
6
|
-
let(:context) { DataMigrate::MigrationContext.new("spec/db/data") }
|
7
|
-
let(:schema_context) { ActiveRecord::MigrationContext.new("spec/db/migrate", ActiveRecord::Base.connection.schema_migration) }
|
8
|
-
let(:db_config) do
|
9
|
-
{
|
10
|
-
adapter: "sqlite3",
|
11
|
-
database: "spec/db/test.db"
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
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
|
20
|
-
|
21
|
-
after do
|
22
|
-
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
23
|
-
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "migrate" do
|
27
|
-
it "migrates existing file" do
|
28
|
-
context.migrate(nil)
|
29
|
-
context.migrations_status
|
30
|
-
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
31
|
-
expect(versions.count).to eq(2)
|
32
|
-
expect(versions).to include("20091231235959")
|
33
|
-
expect(versions).to include("20171231235959")
|
34
|
-
end
|
35
|
-
|
36
|
-
it "undo migration" do
|
37
|
-
context.migrate(nil)
|
38
|
-
context.run(:down, 20171231235959)
|
39
|
-
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
40
|
-
expect(versions.count).to eq(1)
|
41
|
-
expect(versions).to include("20091231235959")
|
42
|
-
end
|
43
|
-
|
44
|
-
it "does not do anything if migration is undone twice" do
|
45
|
-
context.migrate(nil)
|
46
|
-
expect {
|
47
|
-
context.run(:down, 20171231235959)
|
48
|
-
}.to output(/Undoing SuperUpdate/).to_stdout
|
49
|
-
expect {
|
50
|
-
context.run(:down, 20171231235959)
|
51
|
-
}.not_to output(/Undoing SuperUpdate/).to_stdout
|
52
|
-
end
|
53
|
-
|
54
|
-
it "runs a specific migration" do
|
55
|
-
context.run(:up, 20171231235959)
|
56
|
-
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
57
|
-
expect(versions.count).to eq(1)
|
58
|
-
expect(versions).to include("20171231235959")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "does not do anything if migration is ran twice" do
|
62
|
-
expect {
|
63
|
-
context.run(:up, 20171231235959)
|
64
|
-
}.to output(/Doing SuperUpdate/).to_stdout
|
65
|
-
expect {
|
66
|
-
context.run(:down, 20171231235959)
|
67
|
-
}.not_to output(/Doing SuperUpdate/).to_stdout
|
68
|
-
end
|
69
|
-
|
70
|
-
it "alerts for an invalid specific migration" do
|
71
|
-
expect {
|
72
|
-
context.run(:up, 201712312)
|
73
|
-
}.to raise_error(
|
74
|
-
ActiveRecord::UnknownMigrationVersionError,
|
75
|
-
/No migration with version number 201712312/
|
76
|
-
)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "rolls back latest migration" do
|
80
|
-
context.migrate(nil)
|
81
|
-
expect {
|
82
|
-
context.rollback
|
83
|
-
}.to output(/Undoing SuperUpdate/).to_stdout
|
84
|
-
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
85
|
-
expect(versions.count).to eq(1)
|
86
|
-
expect(versions).to include("20091231235959")
|
87
|
-
end
|
88
|
-
|
89
|
-
it "rolls back 2 migrations" do
|
90
|
-
context.migrate(nil)
|
91
|
-
schema_context.migrate(nil)
|
92
|
-
expect {
|
93
|
-
context.rollback(2)
|
94
|
-
}.to output(/Undoing SomeName/).to_stdout
|
95
|
-
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
96
|
-
expect(versions.count).to eq(0)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "rolls back 2 migrations" do
|
100
|
-
context.migrate(nil)
|
101
|
-
expect {
|
102
|
-
context.rollback(2)
|
103
|
-
}.to output(/Undoing SomeName/).to_stdout
|
104
|
-
versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
|
105
|
-
expect(versions.count).to eq(0)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
@@ -1,36 +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(:fixture_file_timestamps) do
|
8
|
-
%w[20091231235959 20101231235959 20111231235959]
|
9
|
-
end
|
10
|
-
|
11
|
-
before do
|
12
|
-
DataMigrate::RailsHelper.schema_migration.create_table
|
13
|
-
DataMigrate::RailsHelper.data_schema_migration.create_table
|
14
|
-
|
15
|
-
fixture_file_timestamps.map do |t|
|
16
|
-
DataMigrate::RailsHelper.data_schema_migration.create_version(t)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
after do
|
21
|
-
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
22
|
-
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".dump" do
|
26
|
-
it "writes the define method with the version key to the stream" do
|
27
|
-
stream = StringIO.new
|
28
|
-
DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
29
|
-
stream.rewind
|
30
|
-
|
31
|
-
last_version = fixture_file_timestamps.last
|
32
|
-
expected = "DataMigrate::Data.define(version: #{last_version})"
|
33
|
-
expect(stream.read).to include expected
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::SchemaMigration do
|
6
|
-
let(:subject) { DataMigrate::SchemaMigration }
|
7
|
-
let(:migration_path) { "spec/db/migrate" }
|
8
|
-
let(:fixture_file_timestamps) do
|
9
|
-
%w[20091231235959 20101231235959 20111231235959]
|
10
|
-
end
|
11
|
-
let(:db_config) do
|
12
|
-
{
|
13
|
-
adapter: "sqlite3",
|
14
|
-
database: "spec/db/test.db"
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
before do
|
19
|
-
ActiveRecord::Base.establish_connection(db_config)
|
20
|
-
DataMigrate::RailsHelper.schema_migration.create_table
|
21
|
-
DataMigrate::RailsHelper.data_schema_migration.create_table
|
22
|
-
end
|
23
|
-
|
24
|
-
after do
|
25
|
-
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
26
|
-
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
27
|
-
end
|
28
|
-
|
29
|
-
describe :pending_schema_migrations do
|
30
|
-
it "list sorted schema migrations" do
|
31
|
-
expect(subject).to receive(:migrations_paths) {
|
32
|
-
migration_path
|
33
|
-
}
|
34
|
-
|
35
|
-
migrations = subject.pending_schema_migrations
|
36
|
-
|
37
|
-
expect(migrations.count).to eq 2
|
38
|
-
expect(migrations[0][:version]).to eq(20131111111111)
|
39
|
-
expect(migrations[1][:version]).to eq(20202020202011)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe :run do
|
44
|
-
it "can run up task" do
|
45
|
-
expect {
|
46
|
-
subject.run(:up, migration_path, 20202020202011)
|
47
|
-
}.to output(/20202020202011 DbMigration: migrating/).to_stdout
|
48
|
-
versions = DataMigrate::RailsHelper.schema_migration.normalized_versions
|
49
|
-
expect(versions.first).to eq("20202020202011")
|
50
|
-
end
|
51
|
-
|
52
|
-
it "can run down task" do
|
53
|
-
subject.run(:up, migration_path, 20202020202011)
|
54
|
-
|
55
|
-
expect {
|
56
|
-
subject.run(:down, migration_path, 20202020202011)
|
57
|
-
}.to output(/Undoing DbMigration/).to_stdout
|
58
|
-
|
59
|
-
versions = DataMigrate::RailsHelper.schema_migration.normalized_versions
|
60
|
-
|
61
|
-
expect(versions.count).to eq(0)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe :migrations_paths do
|
66
|
-
context 'when a db_name is configured' do
|
67
|
-
let(:config) { double(:config) }
|
68
|
-
let(:paths) { ['spec/db/migrate', 'spec/db/migrate/other'] }
|
69
|
-
let(:specification_name) { "primary" }
|
70
|
-
let(:config_options) do
|
71
|
-
if Gem::Dependency.new("railties", "~> 6.1").match?("railties", Gem.loaded_specs["railties"].version)
|
72
|
-
{ env_name: Rails.env, spec_name: specification_name }
|
73
|
-
else
|
74
|
-
{ env_name: Rails.env, name: specification_name }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
before do
|
79
|
-
@original_config_spec_name = DataMigrate.config.spec_name
|
80
|
-
|
81
|
-
DataMigrate.configure do |config|
|
82
|
-
config.spec_name = specification_name
|
83
|
-
end
|
84
|
-
|
85
|
-
allow(ActiveRecord::Base.configurations)
|
86
|
-
.to receive(:configs_for)
|
87
|
-
.with(config_options)
|
88
|
-
.and_return(config)
|
89
|
-
allow(config).to receive(:migrations_paths).and_return(paths)
|
90
|
-
end
|
91
|
-
|
92
|
-
after do
|
93
|
-
DataMigrate.configure do |config|
|
94
|
-
config.spec_name = @original_config_spec_name
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'lists schema migration paths' do
|
99
|
-
expect(subject.migrations_paths.size).to eq(paths.count)
|
100
|
-
expect(subject.migrations_paths).to eq(paths)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::StatusService do
|
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("railties", ">= 6.1").match?("railties", Gem.loaded_specs["railties"].version)
|
11
|
-
ActiveRecord::Base.connection_db_config
|
12
|
-
else
|
13
|
-
ActiveRecord::Base.configurations.configs_for.first
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "table does not exists" do
|
18
|
-
before do
|
19
|
-
allow_any_instance_of(subject).to receive(:table_name) { "bogus"}
|
20
|
-
|
21
|
-
subject.dump(connection_db_config, stream)
|
22
|
-
stream.rewind
|
23
|
-
end
|
24
|
-
|
25
|
-
it "show error message" do
|
26
|
-
expect(stream_data).to include("Data migrations table does not exist")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "table exists" do
|
31
|
-
let(:fixture_file_timestamps) do
|
32
|
-
%w[20091231235959 20101231235959 20111231235959]
|
33
|
-
end
|
34
|
-
|
35
|
-
before do
|
36
|
-
DataMigrate::RailsHelper.schema_migration.create_table
|
37
|
-
DataMigrate::RailsHelper.data_schema_migration.create_table
|
38
|
-
|
39
|
-
fixture_file_timestamps.map do |t|
|
40
|
-
DataMigrate::RailsHelper.data_schema_migration.create_version(t)
|
41
|
-
end
|
42
|
-
|
43
|
-
subject.dump(connection_db_config, stream)
|
44
|
-
stream.rewind
|
45
|
-
end
|
46
|
-
|
47
|
-
after do
|
48
|
-
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
49
|
-
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
50
|
-
end
|
51
|
-
|
52
|
-
it "shows successfully executed migration" do
|
53
|
-
expected = " up 20091231235959 Some name"
|
54
|
-
expect(stream_data).to include expected
|
55
|
-
end
|
56
|
-
|
57
|
-
it "excludes files without .rb extension" do
|
58
|
-
expected = "20181128000207 Excluded file"
|
59
|
-
expect(stream_data).to_not include expected
|
60
|
-
end
|
61
|
-
|
62
|
-
it "shows missing file migration" do
|
63
|
-
expected = " up 20101231235959 ********** NO FILE **********"
|
64
|
-
expect(stream_data).to include expected
|
65
|
-
end
|
66
|
-
|
67
|
-
it "shows migration that has not run yet" do
|
68
|
-
expected = " down 20171231235959 Super update"
|
69
|
-
expect(stream_data).to include expected
|
70
|
-
end
|
71
|
-
|
72
|
-
it "outputs migrations in chronological order" do
|
73
|
-
expect(stream_data.index("20091231235959")).to be < stream_data.index("20111231235959")
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::Tasks::DataMigrateTasks do
|
6
|
-
let(:db_config) do
|
7
|
-
{
|
8
|
-
adapter: "sqlite3",
|
9
|
-
database: "spec/db/test.db"
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
before do
|
14
|
-
ActiveRecord::Base.establish_connection(db_config)
|
15
|
-
DataMigrate::RailsHelper.schema_migration.create_table
|
16
|
-
DataMigrate::RailsHelper.data_schema_migration.create_table
|
17
|
-
end
|
18
|
-
|
19
|
-
after do
|
20
|
-
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
21
|
-
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
22
|
-
end
|
23
|
-
|
24
|
-
describe :dump do
|
25
|
-
before do
|
26
|
-
allow(DataMigrate::DatabaseTasks).to receive(:db_dir).and_return("spec/db")
|
27
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'when not given a separate db config' do
|
31
|
-
it 'does not override the default connection' do
|
32
|
-
expect(ActiveRecord::Base).not_to receive(:establish_connection)
|
33
|
-
expect(DataMigrate::SchemaDumper).to receive(:dump)
|
34
|
-
|
35
|
-
DataMigrate::Tasks::DataMigrateTasks.dump
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'when given a separate db config' do
|
40
|
-
let(:override_config) do
|
41
|
-
{
|
42
|
-
'host' => '127.0.0.1',
|
43
|
-
'database' => 'other_test',
|
44
|
-
'adapter' => 'sqlite3',
|
45
|
-
'username' => 'root',
|
46
|
-
'password' => nil,
|
47
|
-
}
|
48
|
-
end
|
49
|
-
let(:paths) { ["spec/db/migrate"] }
|
50
|
-
|
51
|
-
before do
|
52
|
-
DataMigrate.configure do |config|
|
53
|
-
config.db_configuration = override_config
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'overrides the default connection' do
|
58
|
-
expect(ActiveRecord::Base).to receive(:establish_connection).with(override_config)
|
59
|
-
DataMigrate::Tasks::DataMigrateTasks.dump
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe :migrate do
|
65
|
-
it "first run should run the first pending migration" do
|
66
|
-
expect { DataMigrate::Tasks::DataMigrateTasks.migrate }.to output(/20091231235959 SomeName: migrating/).to_stdout
|
67
|
-
end
|
68
|
-
|
69
|
-
it "second run should run the second pending migration" do
|
70
|
-
expect { DataMigrate::Tasks::DataMigrateTasks.migrate }.to output(/20171231235959 SuperUpdate: migrating/).to_stdout
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe :abort_if_pending_migrations do
|
75
|
-
subject { DataMigrate::Tasks::DataMigrateTasks.abort_if_pending_migrations(migrations, message) }
|
76
|
-
|
77
|
-
let(:message) { "ABORT_MESSAGE" }
|
78
|
-
|
79
|
-
context "when there are no pending migrations" do
|
80
|
-
let(:migrations) { [] }
|
81
|
-
|
82
|
-
it "shouldn't do anything" do
|
83
|
-
expect { subject }.to_not raise_error
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "when there are pending migrations" do
|
88
|
-
let(:migrations) do
|
89
|
-
[{
|
90
|
-
name: "A",
|
91
|
-
version: 1
|
92
|
-
}, {
|
93
|
-
name: 'B',
|
94
|
-
version: 2
|
95
|
-
}]
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should abort with given message and print names and versions of pending migrations" do
|
99
|
-
expect { subject }
|
100
|
-
.to raise_error(SystemExit, message)
|
101
|
-
.and output(match(/You have #{migrations.count} pending migrations:/)
|
102
|
-
.and match(Regexp.new(migrations.map { |m| m.slice(:version, :name)
|
103
|
-
.values.join("\\W+") }.join("\\W+")))).to_stdout
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe ".status" do
|
109
|
-
before do
|
110
|
-
allow(Rails).to receive(:root) { "." }
|
111
|
-
allow(Rails).to receive(:application) { OpenStruct.new(config: OpenStruct.new(paths: { "db/migrate" => ["spec/db/migrate"] })) }
|
112
|
-
|
113
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should display data migration status" do
|
117
|
-
expect {
|
118
|
-
DataMigrate::Tasks::DataMigrateTasks.status
|
119
|
-
}.to output(/up 20091231235959 Some name/).to_stdout
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should display schema and data migration status" do
|
123
|
-
expect {
|
124
|
-
DataMigrate::Tasks::DataMigrateTasks.status_with_schema
|
125
|
-
}.to output(match(/up data 20091231235959 Some name/)
|
126
|
-
.and match(/down schema 20131111111111 Late migration/)).to_stdout
|
127
|
-
end
|
128
|
-
end
|
129
|
-
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,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rails/generators'
|
3
|
-
require 'rails/generators/migration'
|
4
|
-
require 'generators/data_migration/data_migration_generator'
|
5
|
-
|
6
|
-
describe DataMigrate::Generators::DataMigrationGenerator do
|
7
|
-
subject { DataMigrate::Generators::DataMigrationGenerator }
|
8
|
-
|
9
|
-
describe :next_migration_number do
|
10
|
-
it "next migration" do
|
11
|
-
Timecop.freeze("2016-12-03 22:15:26 -0800") do
|
12
|
-
if ActiveRecord.version >= Gem::Version.new('7.0')
|
13
|
-
expect(ActiveRecord).to receive(:timestamped_migrations) { true }
|
14
|
-
else
|
15
|
-
expect(ActiveRecord::Base).to receive(:timestamped_migrations) { true }
|
16
|
-
end
|
17
|
-
expect(subject.next_migration_number(1).to_s).to eq("20161204061526")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe :migration_base_class_name do
|
23
|
-
subject { generator.send(:migration_base_class_name) }
|
24
|
-
|
25
|
-
let(:generator) { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) }
|
26
|
-
|
27
|
-
it "returns the correct base class name" do
|
28
|
-
is_expected.to eq("ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe :create_data_migration do
|
33
|
-
subject { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) }
|
34
|
-
|
35
|
-
let(:data_migrations_file_path) { 'abc/my_migration.rb' }
|
36
|
-
|
37
|
-
context 'when custom data migrations path has a trailing slash' do
|
38
|
-
before do
|
39
|
-
DataMigrate.config.data_migrations_path = 'abc/'
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'returns correct file path' do
|
43
|
-
is_expected.to receive(:migration_template).with(
|
44
|
-
'data_migration.rb', data_migrations_file_path
|
45
|
-
)
|
46
|
-
|
47
|
-
subject.create_data_migration
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'when custom data migrations path does not have a trailing slash' do
|
52
|
-
before do
|
53
|
-
DataMigrate.config.data_migrations_path = 'abc'
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'returns correct file path' do
|
57
|
-
is_expected.to receive(:migration_template).with(
|
58
|
-
'data_migration.rb', data_migrations_file_path
|
59
|
-
)
|
60
|
-
|
61
|
-
subject.create_data_migration
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe ".source_root" do
|
67
|
-
subject { described_class.source_root }
|
68
|
-
|
69
|
-
let(:default_source_root) do
|
70
|
-
File.expand_path(
|
71
|
-
File.dirname(File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb"))
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
|
-
it { is_expected.to eq default_source_root }
|
76
|
-
|
77
|
-
context "when DateMigrate.config.data_template_path is set" do
|
78
|
-
before do
|
79
|
-
@before = DataMigrate.config.data_template_path
|
80
|
-
DataMigrate.configure do |config|
|
81
|
-
config.data_template_path = data_template_path
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
let(:data_template_path) do
|
86
|
-
File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb")
|
87
|
-
end
|
88
|
-
let(:expected_source_root) { File.dirname(data_template_path) }
|
89
|
-
|
90
|
-
after do
|
91
|
-
DataMigrate.configure do |config|
|
92
|
-
config.data_template_path = @before
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
it "reads directory from config data template path" do
|
97
|
-
is_expected.to eq expected_source_root
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'rails'
|
3
|
-
require 'sqlite3'
|
4
|
-
require 'data_migrate'
|
5
|
-
require 'pry'
|
6
|
-
require 'timecop'
|
7
|
-
|
8
|
-
RSpec.configure do |config|
|
9
|
-
config.mock_with :rspec do |mocks|
|
10
|
-
mocks.verify_partial_doubles = true
|
11
|
-
end
|
12
|
-
|
13
|
-
config.after(:each) do
|
14
|
-
DataMigrate.configure do |config|
|
15
|
-
config.data_migrations_path = @prev_data_migrations_path
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
config.before(:each) do |example|
|
20
|
-
if example.metadata[:no_override]
|
21
|
-
else
|
22
|
-
@prev_data_migrations_path = DataMigrate.config.data_migrations_path
|
23
|
-
DataMigrate.configure do |config|
|
24
|
-
config.data_migrations_path = "spec/db/data"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/tasks/.gitkeep
DELETED
File without changes
|