data_migrate 8.5.0 → 9.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/.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
@@ -3,32 +3,27 @@
|
|
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 }
|
7
|
+
let(:migration_path) { "spec/db/migrate" }
|
8
|
+
let(:fixture_file_timestamps) do
|
9
|
+
%w[20091231235959 20101231235959 20111231235959]
|
10
|
+
end
|
15
11
|
let(:db_config) do
|
16
12
|
{
|
17
13
|
adapter: "sqlite3",
|
18
14
|
database: "spec/db/test.db"
|
19
15
|
}
|
20
16
|
end
|
21
|
-
let(:fixture_file_timestamps) do
|
22
|
-
%w[20091231235959 20101231235959 20111231235959]
|
23
|
-
end
|
24
17
|
|
25
18
|
before do
|
26
19
|
ActiveRecord::Base.establish_connection(db_config)
|
27
|
-
|
20
|
+
DataMigrate::RailsHelper.schema_migration.create_table
|
21
|
+
DataMigrate::RailsHelper.data_schema_migration.create_table
|
28
22
|
end
|
29
23
|
|
30
24
|
after do
|
31
|
-
ActiveRecord::Migration.drop_table("
|
25
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
26
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
32
27
|
end
|
33
28
|
|
34
29
|
describe :pending_schema_migrations do
|
@@ -36,6 +31,7 @@ describe DataMigrate::SchemaMigration do
|
|
36
31
|
expect(subject).to receive(:migrations_paths) {
|
37
32
|
migration_path
|
38
33
|
}
|
34
|
+
|
39
35
|
migrations = subject.pending_schema_migrations
|
40
36
|
|
41
37
|
expect(migrations.count).to eq 2
|
@@ -45,55 +41,64 @@ describe DataMigrate::SchemaMigration do
|
|
45
41
|
end
|
46
42
|
|
47
43
|
describe :run do
|
48
|
-
it do
|
44
|
+
it "can run up task" do
|
49
45
|
expect {
|
50
46
|
subject.run(:up, migration_path, 20202020202011)
|
51
47
|
}.to output(/20202020202011 DbMigration: migrating/).to_stdout
|
52
|
-
versions =
|
48
|
+
versions = DataMigrate::RailsHelper.schema_migration.normalized_versions
|
53
49
|
expect(versions.first).to eq("20202020202011")
|
54
50
|
end
|
55
51
|
|
56
|
-
it "
|
52
|
+
it "can run down task" do
|
57
53
|
subject.run(:up, migration_path, 20202020202011)
|
54
|
+
|
58
55
|
expect {
|
59
56
|
subject.run(:down, migration_path, 20202020202011)
|
60
57
|
}.to output(/Undoing DbMigration/).to_stdout
|
61
|
-
|
58
|
+
|
59
|
+
versions = DataMigrate::RailsHelper.schema_migration.normalized_versions
|
60
|
+
|
62
61
|
expect(versions.count).to eq(0)
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
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 }
|
77
75
|
end
|
76
|
+
end
|
78
77
|
|
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)
|
78
|
+
before do
|
79
|
+
@original_config_spec_name = DataMigrate.config.spec_name
|
88
80
|
|
89
|
-
|
81
|
+
DataMigrate.configure do |config|
|
82
|
+
config.spec_name = specification_name
|
90
83
|
end
|
91
84
|
|
92
|
-
|
93
|
-
|
94
|
-
|
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
95
|
end
|
96
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
|
97
102
|
end
|
98
103
|
end
|
99
104
|
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("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
|
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,44 @@ describe DataMigrate::StatusService do
|
|
34
33
|
end
|
35
34
|
|
36
35
|
before do
|
37
|
-
|
38
|
-
|
39
|
-
ActiveRecord::Base.establish_connection(db_config)
|
36
|
+
DataMigrate::RailsHelper.schema_migration.create_table
|
37
|
+
DataMigrate::RailsHelper.data_schema_migration.create_table
|
40
38
|
|
41
|
-
|
42
|
-
|
39
|
+
fixture_file_timestamps.map do |t|
|
40
|
+
DataMigrate::RailsHelper.data_schema_migration.create_version(t)
|
41
|
+
end
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
VALUES #{fixture_file_timestamps.map { |t| "(#{t})" }.join(', ')}
|
47
|
-
SQL
|
48
|
-
|
49
|
-
allow_any_instance_of(service).to receive(:root_folder) { "./" }
|
43
|
+
subject.dump(connection_db_config, stream)
|
44
|
+
stream.rewind
|
50
45
|
end
|
51
46
|
|
52
47
|
after do
|
53
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
48
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
49
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
54
50
|
end
|
55
51
|
|
56
52
|
it "shows successfully executed migration" do
|
57
|
-
stream = StringIO.new
|
58
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
59
|
-
stream.rewind
|
60
|
-
|
61
53
|
expected = " up 20091231235959 Some name"
|
62
|
-
expect(
|
54
|
+
expect(stream_data).to include expected
|
63
55
|
end
|
64
56
|
|
65
57
|
it "excludes files without .rb extension" do
|
66
|
-
stream = StringIO.new
|
67
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
68
|
-
stream.rewind
|
69
|
-
|
70
58
|
expected = "20181128000207 Excluded file"
|
71
|
-
expect(
|
59
|
+
expect(stream_data).to_not include expected
|
72
60
|
end
|
73
61
|
|
74
62
|
it "shows missing file migration" do
|
75
|
-
stream = StringIO.new
|
76
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
77
|
-
stream.rewind
|
78
|
-
|
79
63
|
expected = " up 20101231235959 ********** NO FILE **********"
|
80
|
-
|
81
|
-
expect(s).to include expected
|
64
|
+
expect(stream_data).to include expected
|
82
65
|
end
|
83
66
|
|
84
67
|
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
68
|
expected = " down 20171231235959 Super update"
|
90
|
-
|
91
|
-
expect(s).to include expected
|
69
|
+
expect(stream_data).to include expected
|
92
70
|
end
|
93
71
|
|
94
72
|
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")
|
73
|
+
expect(stream_data.index("20091231235959")).to be < stream_data.index("20111231235959")
|
100
74
|
end
|
101
75
|
end
|
102
76
|
end
|
@@ -3,33 +3,40 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe DataMigrate::Tasks::DataMigrateTasks do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
13
23
|
|
24
|
+
describe :dump do
|
14
25
|
before do
|
15
|
-
allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
|
16
26
|
allow(DataMigrate::DatabaseTasks).to receive(:db_dir).and_return("spec/db")
|
17
|
-
|
18
|
-
|
19
|
-
after do
|
20
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
27
|
+
DataMigrate::Tasks::DataMigrateTasks.migrate
|
21
28
|
end
|
22
29
|
|
23
30
|
context 'when not given a separate db config' do
|
24
31
|
it 'does not override the default connection' do
|
25
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
26
32
|
expect(ActiveRecord::Base).not_to receive(:establish_connection)
|
27
33
|
expect(DataMigrate::SchemaDumper).to receive(:dump)
|
34
|
+
|
28
35
|
DataMigrate::Tasks::DataMigrateTasks.dump
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
32
|
-
context 'when given ' do
|
39
|
+
context 'when given a separate db config' do
|
33
40
|
let(:override_config) do
|
34
41
|
{
|
35
42
|
'host' => '127.0.0.1',
|
@@ -39,6 +46,7 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
39
46
|
'password' => nil,
|
40
47
|
}
|
41
48
|
end
|
49
|
+
let(:paths) { ["spec/db/migrate"] }
|
42
50
|
|
43
51
|
before do
|
44
52
|
DataMigrate.configure do |config|
|
@@ -47,7 +55,6 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
47
55
|
end
|
48
56
|
|
49
57
|
it 'overrides the default connection' do
|
50
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
51
58
|
expect(ActiveRecord::Base).to receive(:establish_connection).with(override_config)
|
52
59
|
DataMigrate::Tasks::DataMigrateTasks.dump
|
53
60
|
end
|
@@ -55,32 +62,12 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
55
62
|
end
|
56
63
|
|
57
64
|
describe :migrate do
|
58
|
-
|
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")
|
65
|
+
it "first run should run the first pending migration" do
|
66
|
+
expect { DataMigrate::Tasks::DataMigrateTasks.migrate }.to output(/20091231235959 SomeName: migrating/).to_stdout
|
72
67
|
end
|
73
68
|
|
74
|
-
it do
|
75
|
-
|
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
|
69
|
+
it "second run should run the second pending migration" do
|
70
|
+
expect { DataMigrate::Tasks::DataMigrateTasks.migrate }.to output(/20171231235959 SuperUpdate: migrating/).to_stdout
|
84
71
|
end
|
85
72
|
end
|
86
73
|
|
@@ -111,43 +98,21 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
111
98
|
it "should abort with given message and print names and versions of pending migrations" do
|
112
99
|
expect { subject }
|
113
100
|
.to raise_error(SystemExit, message)
|
114
|
-
.and output(
|
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
|
115
104
|
end
|
116
105
|
end
|
117
106
|
end
|
118
107
|
|
119
|
-
describe
|
120
|
-
let(:db_config) do
|
121
|
-
{
|
122
|
-
adapter: "sqlite3",
|
123
|
-
database: "spec/db/test.db"
|
124
|
-
}
|
125
|
-
end
|
126
|
-
|
108
|
+
describe ".status" do
|
127
109
|
before do
|
128
|
-
|
129
|
-
|
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
|
110
|
+
allow(Rails).to receive(:root) { "." }
|
111
|
+
allow(Rails).to receive(:application) { OpenStruct.new(config: OpenStruct.new(paths: { "db/migrate" => ["spec/db/migrate"] })) }
|
143
112
|
|
144
113
|
DataMigrate::Tasks::DataMigrateTasks.migrate
|
145
114
|
end
|
146
115
|
|
147
|
-
after do
|
148
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
149
|
-
end
|
150
|
-
|
151
116
|
it "should display data migration status" do
|
152
117
|
expect {
|
153
118
|
DataMigrate::Tasks::DataMigrateTasks.status
|
data/spec/spec_helper.rb
CHANGED
@@ -20,14 +20,8 @@ RSpec.configure do |config|
|
|
20
20
|
if example.metadata[:no_override]
|
21
21
|
else
|
22
22
|
@prev_data_migrations_path = DataMigrate.config.data_migrations_path
|
23
|
-
|
24
|
-
|
25
|
-
config.data_migrations_path = "spec/db/data"
|
26
|
-
end
|
27
|
-
else
|
28
|
-
DataMigrate.configure do |config|
|
29
|
-
config.data_migrations_path = "spec/db/6.0"
|
30
|
-
end
|
23
|
+
DataMigrate.configure do |config|
|
24
|
+
config.data_migrations_path = "spec/db/data"
|
31
25
|
end
|
32
26
|
end
|
33
27
|
end
|
data/tasks/databases.rake
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'data_migrate/tasks/data_migrate_tasks'
|
2
4
|
|
3
5
|
namespace :db do
|
4
6
|
namespace :migrate do
|
5
7
|
desc "Migrate the database data and schema (options: VERSION=x, VERBOSE=false)."
|
6
8
|
task :with_data => :environment do
|
7
|
-
DataMigrate::DataMigrator.
|
9
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
8
10
|
|
9
11
|
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
10
12
|
target_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
@@ -56,7 +58,7 @@ namespace :db do
|
|
56
58
|
namespace :redo do
|
57
59
|
desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
|
58
60
|
task :with_data => :environment do
|
59
|
-
|
61
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
60
62
|
if ENV["VERSION"]
|
61
63
|
Rake::Task["db:migrate:down:with_data"].invoke
|
62
64
|
Rake::Task["db:migrate:up:with_data"].invoke
|
@@ -72,7 +74,7 @@ namespace :db do
|
|
72
74
|
task :with_data => :environment do
|
73
75
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
74
76
|
raise "VERSION is required" unless version
|
75
|
-
DataMigrate::DataMigrator.
|
77
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
76
78
|
run_both = ENV["BOTH"] == "true"
|
77
79
|
migrations = DataMigrate::DatabaseTasks.pending_migrations.keep_if{|m| m[:version] == version}
|
78
80
|
|
@@ -94,7 +96,7 @@ namespace :db do
|
|
94
96
|
task :with_data => :environment do
|
95
97
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
96
98
|
raise "VERSION is required" unless version
|
97
|
-
DataMigrate::DataMigrator.
|
99
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
98
100
|
run_both = ENV["BOTH"] == "true"
|
99
101
|
migrations = DataMigrate::DatabaseTasks.past_migrations.keep_if{|m| m[:version] == version}
|
100
102
|
|
@@ -123,7 +125,7 @@ namespace :db do
|
|
123
125
|
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
124
126
|
task :with_data => :environment do
|
125
127
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
126
|
-
DataMigrate::DataMigrator.
|
128
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
127
129
|
DataMigrate::DatabaseTasks.past_migrations[0..(step - 1)].each do | past_migration |
|
128
130
|
DataMigrate::DatabaseTasks.run_migration(past_migration, :down)
|
129
131
|
end
|
@@ -136,7 +138,7 @@ namespace :db do
|
|
136
138
|
namespace :forward do
|
137
139
|
desc 'Pushes the schema to the next version (specify steps w/ STEP=n).'
|
138
140
|
task :with_data => :environment do
|
139
|
-
DataMigrate::DataMigrator.
|
141
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
140
142
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
141
143
|
DataMigrate::DatabaseTasks.forward(step)
|
142
144
|
Rake::Task["db:_dump"].invoke
|
@@ -147,7 +149,7 @@ namespace :db do
|
|
147
149
|
namespace :version do
|
148
150
|
desc "Retrieves the current schema version numbers for data and schema migrations"
|
149
151
|
task :with_data => :environment do
|
150
|
-
DataMigrate::DataMigrator.
|
152
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
151
153
|
puts "Current Schema version: #{ActiveRecord::Migrator.current_version}"
|
152
154
|
puts "Current Data version: #{DataMigrate::DataMigrator.current_version}"
|
153
155
|
end
|
@@ -200,7 +202,7 @@ namespace :data do
|
|
200
202
|
namespace :migrate do
|
201
203
|
desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
|
202
204
|
task :redo => :environment do
|
203
|
-
DataMigrate::DataMigrator.
|
205
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
204
206
|
if ENV["VERSION"]
|
205
207
|
Rake::Task["data:migrate:down"].invoke
|
206
208
|
Rake::Task["data:migrate:up"].invoke
|
@@ -212,7 +214,7 @@ namespace :data do
|
|
212
214
|
|
213
215
|
desc 'Runs the "up" for a given migration VERSION.'
|
214
216
|
task :up => :environment do
|
215
|
-
DataMigrate::DataMigrator.
|
217
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
216
218
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
217
219
|
raise "VERSION is required" unless version
|
218
220
|
DataMigrate::DataMigrator.run(:up, DataMigrate::DatabaseTasks.data_migrations_path, version)
|
@@ -223,7 +225,7 @@ namespace :data do
|
|
223
225
|
task :down => :environment do
|
224
226
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
225
227
|
raise "VERSION is required" unless version
|
226
|
-
DataMigrate::DataMigrator.
|
228
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
227
229
|
DataMigrate::DataMigrator.run(:down, DataMigrate::DatabaseTasks.data_migrations_path, version)
|
228
230
|
Rake::Task["data:dump"].invoke
|
229
231
|
end
|
@@ -236,7 +238,7 @@ namespace :data do
|
|
236
238
|
|
237
239
|
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
238
240
|
task :rollback => :environment do
|
239
|
-
DataMigrate::DataMigrator.
|
241
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
240
242
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
241
243
|
DataMigrate::DataMigrator.rollback(DataMigrate::DatabaseTasks.data_migrations_path, step)
|
242
244
|
Rake::Task["data:dump"].invoke
|
@@ -244,7 +246,7 @@ namespace :data do
|
|
244
246
|
|
245
247
|
desc 'Pushes the schema to the next version (specify steps w/ STEP=n).'
|
246
248
|
task :forward => :environment do
|
247
|
-
DataMigrate::DataMigrator.
|
249
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
248
250
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
249
251
|
# TODO: No worky for .forward
|
250
252
|
# DataMigrate::DataMigrator.forward('db/data/', step)
|
@@ -257,7 +259,7 @@ namespace :data do
|
|
257
259
|
|
258
260
|
desc "Retrieves the current schema version number for data migrations"
|
259
261
|
task :version => :environment do
|
260
|
-
DataMigrate::DataMigrator.
|
262
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
261
263
|
puts "Current data version: #{DataMigrate::DataMigrator.current_version}"
|
262
264
|
end
|
263
265
|
|