data_migrate 10.0.3.rc → 11.0.0.rc
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 +4 -4
- data/.github/workflows/gempush.yml +6 -8
- data/.gitignore +0 -1
- data/Appraisals +10 -5
- data/Changelog.md +32 -6
- data/Gemfile +0 -1
- data/Gemfile.lock +188 -0
- data/README.md +13 -4
- data/data_migrate.gemspec +2 -2
- data/gemfiles/rails_6.1.gemfile +0 -1
- data/gemfiles/rails_6.1.gemfile.lock +233 -0
- data/gemfiles/rails_7.0.gemfile +1 -2
- data/gemfiles/rails_7.0.gemfile.lock +234 -0
- data/gemfiles/{rails_6.0.gemfile → rails_7.1.gemfile} +1 -2
- data/gemfiles/rails_7.1.gemfile.lock +266 -0
- data/gemfiles/rails_7.2.gemfile +7 -0
- data/gemfiles/rails_7.2.gemfile.lock +265 -0
- data/lib/data_migrate/data_migrator.rb +15 -23
- data/lib/data_migrate/data_schema.rb +2 -2
- data/lib/data_migrate/data_schema_migration.rb +24 -7
- data/lib/data_migrate/database_configurations_wrapper.rb +11 -0
- data/lib/data_migrate/database_tasks.rb +194 -48
- data/lib/data_migrate/migration_context.rb +11 -8
- data/lib/data_migrate/rails_helper.rb +90 -0
- data/lib/data_migrate/schema_dumper.rb +1 -1
- data/lib/data_migrate/schema_migration.rb +5 -4
- data/lib/data_migrate/status_service.rb +3 -3
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +13 -14
- data/lib/data_migrate/test.rb +14 -0
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +2 -1
- data/spec/data_migrate/data_migrator_spec.rb +17 -14
- data/spec/data_migrate/data_schema_migration_spec.rb +25 -8
- data/spec/data_migrate/data_spec.rb +1 -1
- data/spec/data_migrate/database_tasks_spec.rb +34 -19
- data/spec/data_migrate/migration_context_spec.rb +25 -9
- data/spec/data_migrate/schema_dumper_spec.rb +6 -3
- data/spec/data_migrate/schema_migration_spec.rb +13 -6
- data/spec/data_migrate/status_service_spec.rb +6 -3
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +13 -14
- data/spec/db/data/20091231235959_some_name.rb +1 -1
- data/spec/db/data/20171231235959_super_update.rb +1 -1
- data/spec/db/migrate/20131111111111_late_migration.rb +1 -1
- data/spec/db/migrate/20202020202011_db_migration.rb +1 -1
- data/tasks/databases.rake +25 -93
- metadata +21 -15
- data/Gemfile.rails6.1 +0 -11
- data/lib/data_migrate/legacy_migrator.rb +0 -22
- data/spec/data_migrate/legacy_migrator_spec.rb +0 -38
@@ -8,10 +8,17 @@ describe DataMigrate::SchemaMigration do
|
|
8
8
|
let(:fixture_file_timestamps) do
|
9
9
|
%w[20091231235959 20101231235959 20111231235959]
|
10
10
|
end
|
11
|
+
let(:db_config) do
|
12
|
+
{
|
13
|
+
adapter: "sqlite3",
|
14
|
+
database: "spec/db/test.db"
|
15
|
+
}
|
16
|
+
end
|
11
17
|
|
12
18
|
before do
|
13
|
-
ActiveRecord::
|
14
|
-
DataMigrate::
|
19
|
+
ActiveRecord::Base.establish_connection(db_config)
|
20
|
+
DataMigrate::RailsHelper.schema_migration.create_table
|
21
|
+
DataMigrate::RailsHelper.data_schema_migration.create_table
|
15
22
|
end
|
16
23
|
|
17
24
|
after do
|
@@ -38,7 +45,7 @@ describe DataMigrate::SchemaMigration do
|
|
38
45
|
expect {
|
39
46
|
subject.run(:up, migration_path, 20202020202011)
|
40
47
|
}.to output(/20202020202011 DbMigration: migrating/).to_stdout
|
41
|
-
versions =
|
48
|
+
versions = DataMigrate::RailsHelper.schema_migration.normalized_versions
|
42
49
|
expect(versions.first).to eq("20202020202011")
|
43
50
|
end
|
44
51
|
|
@@ -49,7 +56,7 @@ describe DataMigrate::SchemaMigration do
|
|
49
56
|
subject.run(:down, migration_path, 20202020202011)
|
50
57
|
}.to output(/Undoing DbMigration/).to_stdout
|
51
58
|
|
52
|
-
versions =
|
59
|
+
versions = DataMigrate::RailsHelper.schema_migration.normalized_versions
|
53
60
|
|
54
61
|
expect(versions.count).to eq(0)
|
55
62
|
end
|
@@ -61,9 +68,9 @@ describe DataMigrate::SchemaMigration do
|
|
61
68
|
let(:paths) { ['spec/db/migrate', 'spec/db/migrate/other'] }
|
62
69
|
let(:specification_name) { "primary" }
|
63
70
|
let(:config_options) do
|
64
|
-
if Gem::Dependency.new("railties", "~> 6.
|
71
|
+
if Gem::Dependency.new("railties", "~> 6.1").match?("railties", Gem.loaded_specs["railties"].version)
|
65
72
|
{ env_name: Rails.env, spec_name: specification_name }
|
66
|
-
|
73
|
+
else
|
67
74
|
{ env_name: Rails.env, name: specification_name }
|
68
75
|
end
|
69
76
|
end
|
@@ -33,9 +33,12 @@ describe DataMigrate::StatusService do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
before do
|
36
|
-
|
37
|
-
DataMigrate::
|
38
|
-
|
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
|
39
42
|
|
40
43
|
subject.dump(connection_db_config, stream)
|
41
44
|
stream.rewind
|
@@ -3,17 +3,17 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe DataMigrate::Tasks::DataMigrateTasks do
|
6
|
-
let(:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
6
|
+
let(:db_config) do
|
7
|
+
{
|
8
|
+
adapter: "sqlite3",
|
9
|
+
database: "spec/db/test.db"
|
10
|
+
}
|
12
11
|
end
|
13
12
|
|
14
13
|
before do
|
15
|
-
ActiveRecord::
|
16
|
-
DataMigrate::
|
14
|
+
ActiveRecord::Base.establish_connection(db_config)
|
15
|
+
DataMigrate::RailsHelper.schema_migration.create_table
|
16
|
+
DataMigrate::RailsHelper.data_schema_migration.create_table
|
17
17
|
end
|
18
18
|
|
19
19
|
after do
|
@@ -28,11 +28,11 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'when not given a separate db config' do
|
31
|
-
it 'does not override the default connection' do
|
31
|
+
it 'does not override the default connection' do
|
32
32
|
expect(ActiveRecord::Base).not_to receive(:establish_connection)
|
33
33
|
expect(DataMigrate::SchemaDumper).to receive(:dump)
|
34
34
|
|
35
|
-
DataMigrate::Tasks::DataMigrateTasks.dump
|
35
|
+
DataMigrate::Tasks::DataMigrateTasks.dump
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -56,8 +56,7 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
56
56
|
|
57
57
|
it 'overrides the default connection' do
|
58
58
|
expect(ActiveRecord::Base).to receive(:establish_connection).with(override_config)
|
59
|
-
|
60
|
-
DataMigrate::Tasks::DataMigrateTasks.dump(connection_db_config)
|
59
|
+
DataMigrate::Tasks::DataMigrateTasks.dump
|
61
60
|
end
|
62
61
|
end
|
63
62
|
end
|
@@ -116,13 +115,13 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
116
115
|
|
117
116
|
it "should display data migration status" do
|
118
117
|
expect {
|
119
|
-
DataMigrate::Tasks::DataMigrateTasks.status
|
118
|
+
DataMigrate::Tasks::DataMigrateTasks.status
|
120
119
|
}.to output(/up 20091231235959 Some name/).to_stdout
|
121
120
|
end
|
122
121
|
|
123
122
|
it "should display schema and data migration status" do
|
124
123
|
expect {
|
125
|
-
DataMigrate::Tasks::DataMigrateTasks.status_with_schema
|
124
|
+
DataMigrate::Tasks::DataMigrateTasks.status_with_schema
|
126
125
|
}.to output(match(/up data 20091231235959 Some name/)
|
127
126
|
.and match(/down schema 20131111111111 Late migration/)).to_stdout
|
128
127
|
end
|
data/tasks/databases.rake
CHANGED
@@ -5,71 +5,16 @@ require 'data_migrate/tasks/data_migrate_tasks'
|
|
5
5
|
namespace :db do
|
6
6
|
namespace :migrate do
|
7
7
|
desc "Migrate the database data and schema (options: VERSION=x, VERBOSE=false)."
|
8
|
-
task :with_data => :
|
9
|
-
|
10
|
-
ActiveRecord::Base.connection_db_config
|
11
|
-
elsif Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
|
12
|
-
ActiveRecord::Base.connection_config
|
13
|
-
end
|
14
|
-
|
15
|
-
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
|
16
|
-
ActiveRecord::Base.establish_connection(db_config)
|
17
|
-
DataMigrate::DataMigrator.assure_data_schema_table
|
18
|
-
|
19
|
-
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
20
|
-
target_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
21
|
-
migrations = []
|
22
|
-
|
23
|
-
if target_version.nil?
|
24
|
-
migrations = DataMigrate::DatabaseTasks.pending_migrations.map{ |m| m.merge(:direction =>:up) }
|
25
|
-
else
|
26
|
-
current_schema_version = ActiveRecord::Migrator.current_version
|
27
|
-
schema_migrations = if target_version > current_schema_version
|
28
|
-
DataMigrate::DatabaseTasks.pending_schema_migrations.keep_if{ |m| m[:version] <= target_version }.map{ |m| m.merge(:direction =>:up) }
|
29
|
-
elsif target_version < current_schema_version
|
30
|
-
DataMigrate::DatabaseTasks.past_migrations.keep_if{ |m| m[:version] > target_version }.map{ |m| m.merge(:direction =>:down) }
|
31
|
-
else # ==
|
32
|
-
[]
|
33
|
-
end
|
34
|
-
|
35
|
-
current_data_version = DataMigrate::DataMigrator.current_version
|
36
|
-
data_migrations = if target_version > current_data_version
|
37
|
-
DataMigrate::DatabaseTasks.pending_data_migrations.keep_if{ |m| m[:version] <= target_version }.map{ |m| m.merge(:direction =>:up) }
|
38
|
-
elsif target_version < current_data_version
|
39
|
-
DataMigrate::DatabaseTasks.past_migrations.keep_if{ |m| m[:version] > target_version }.map{ |m| m.merge(:direction =>:down) }
|
40
|
-
else # ==
|
41
|
-
[]
|
42
|
-
end
|
43
|
-
migrations = if schema_migrations.empty?
|
44
|
-
data_migrations
|
45
|
-
elsif data_migrations.empty?
|
46
|
-
schema_migrations
|
47
|
-
elsif target_version > current_data_version && target_version > current_schema_version
|
48
|
-
DataMigrate::DatabaseTasks.sort_migrations data_migrations, schema_migrations
|
49
|
-
elsif target_version < current_data_version && target_version < current_schema_version
|
50
|
-
DataMigrate::DatabaseTasks.sort_migrations(data_migrations, schema_migrations).reverse
|
51
|
-
elsif target_version > current_data_version && target_version < current_schema_version
|
52
|
-
schema_migrations + data_migrations
|
53
|
-
elsif target_version < current_data_version && target_version > current_schema_version
|
54
|
-
schema_migrations + data_migrations
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
migrations.each do |migration|
|
59
|
-
DataMigrate::DatabaseTasks.run_migration(migration, migration[:direction])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
8
|
+
task :with_data => :load_config do
|
9
|
+
DataMigrate::DatabaseTasks.migrate_with_data
|
63
10
|
Rake::Task["db:_dump"].invoke
|
64
11
|
Rake::Task["data:dump"].invoke
|
65
|
-
ensure
|
66
|
-
ActiveRecord::Base.establish_connection(original_db_config)
|
67
12
|
end
|
68
13
|
|
69
14
|
namespace :redo do
|
70
15
|
desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
|
71
16
|
task :with_data => :environment do
|
72
|
-
|
17
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
73
18
|
if ENV["VERSION"]
|
74
19
|
Rake::Task["db:migrate:down:with_data"].invoke
|
75
20
|
Rake::Task["db:migrate:up:with_data"].invoke
|
@@ -85,7 +30,7 @@ namespace :db do
|
|
85
30
|
task :with_data => :environment do
|
86
31
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
87
32
|
raise "VERSION is required" unless version
|
88
|
-
DataMigrate::DataMigrator.
|
33
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
89
34
|
run_both = ENV["BOTH"] == "true"
|
90
35
|
migrations = DataMigrate::DatabaseTasks.pending_migrations.keep_if{|m| m[:version] == version}
|
91
36
|
|
@@ -107,7 +52,7 @@ namespace :db do
|
|
107
52
|
task :with_data => :environment do
|
108
53
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
109
54
|
raise "VERSION is required" unless version
|
110
|
-
DataMigrate::DataMigrator.
|
55
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
111
56
|
run_both = ENV["BOTH"] == "true"
|
112
57
|
migrations = DataMigrate::DatabaseTasks.past_migrations.keep_if{|m| m[:version] == version}
|
113
58
|
|
@@ -127,10 +72,7 @@ namespace :db do
|
|
127
72
|
namespace :status do
|
128
73
|
desc "Display status of data and schema migrations"
|
129
74
|
task :with_data => :environment do
|
130
|
-
|
131
|
-
ActiveRecord::Base.establish_connection(db_config)
|
132
|
-
DataMigrate::Tasks::DataMigrateTasks.status_with_schema(db_config)
|
133
|
-
end
|
75
|
+
DataMigrate::Tasks::DataMigrateTasks.status_with_schema
|
134
76
|
end
|
135
77
|
end
|
136
78
|
end # END OF MIGRATE NAME SPACE
|
@@ -139,7 +81,7 @@ namespace :db do
|
|
139
81
|
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
140
82
|
task :with_data => :environment do
|
141
83
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
142
|
-
DataMigrate::DataMigrator.
|
84
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
143
85
|
DataMigrate::DatabaseTasks.past_migrations[0..(step - 1)].each do | past_migration |
|
144
86
|
DataMigrate::DatabaseTasks.run_migration(past_migration, :down)
|
145
87
|
end
|
@@ -152,7 +94,7 @@ namespace :db do
|
|
152
94
|
namespace :forward do
|
153
95
|
desc 'Pushes the schema to the next version (specify steps w/ STEP=n).'
|
154
96
|
task :with_data => :environment do
|
155
|
-
DataMigrate::DataMigrator.
|
97
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
156
98
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
157
99
|
DataMigrate::DatabaseTasks.forward(step)
|
158
100
|
Rake::Task["db:_dump"].invoke
|
@@ -163,7 +105,7 @@ namespace :db do
|
|
163
105
|
namespace :version do
|
164
106
|
desc "Retrieves the current schema version numbers for data and schema migrations"
|
165
107
|
task :with_data => :environment do
|
166
|
-
DataMigrate::DataMigrator.
|
108
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
167
109
|
puts "Current Schema version: #{ActiveRecord::Migrator.current_version}"
|
168
110
|
puts "Current Data version: #{DataMigrate::DataMigrator.current_version}"
|
169
111
|
end
|
@@ -204,30 +146,26 @@ namespace :db do
|
|
204
146
|
end
|
205
147
|
end
|
206
148
|
end
|
149
|
+
|
150
|
+
namespace :prepare do
|
151
|
+
desc "Runs setup if database does not exist, or runs data and schema migrations if it does"
|
152
|
+
task with_data: :environment do
|
153
|
+
DataMigrate::DatabaseTasks.prepare_all_with_data
|
154
|
+
end
|
155
|
+
end
|
207
156
|
end
|
208
157
|
|
209
158
|
namespace :data do
|
210
159
|
desc 'Migrate data migrations (options: VERSION=x, VERBOSE=false)'
|
211
160
|
task :migrate => :environment do
|
212
|
-
|
213
|
-
ActiveRecord::Base.connection_db_config
|
214
|
-
elsif Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
|
215
|
-
ActiveRecord::Base.connection_config
|
216
|
-
end
|
217
|
-
|
218
|
-
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
|
219
|
-
ActiveRecord::Base.establish_connection(db_config)
|
220
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
221
|
-
end
|
161
|
+
DataMigrate::Tasks::DataMigrateTasks.migrate
|
222
162
|
Rake::Task["data:dump"].invoke
|
223
|
-
ensure
|
224
|
-
ActiveRecord::Base.establish_connection(original_db_config)
|
225
163
|
end
|
226
164
|
|
227
165
|
namespace :migrate do
|
228
166
|
desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
|
229
167
|
task :redo => :environment do
|
230
|
-
DataMigrate::DataMigrator.
|
168
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
231
169
|
if ENV["VERSION"]
|
232
170
|
Rake::Task["data:migrate:down"].invoke
|
233
171
|
Rake::Task["data:migrate:up"].invoke
|
@@ -239,7 +177,7 @@ namespace :data do
|
|
239
177
|
|
240
178
|
desc 'Runs the "up" for a given migration VERSION.'
|
241
179
|
task :up => :environment do
|
242
|
-
DataMigrate::DataMigrator.
|
180
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
243
181
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
244
182
|
raise "VERSION is required" unless version
|
245
183
|
DataMigrate::DataMigrator.run(:up, DataMigrate::DatabaseTasks.data_migrations_path, version)
|
@@ -250,23 +188,20 @@ namespace :data do
|
|
250
188
|
task :down => :environment do
|
251
189
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
252
190
|
raise "VERSION is required" unless version
|
253
|
-
DataMigrate::DataMigrator.
|
191
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
254
192
|
DataMigrate::DataMigrator.run(:down, DataMigrate::DatabaseTasks.data_migrations_path, version)
|
255
193
|
Rake::Task["data:dump"].invoke
|
256
194
|
end
|
257
195
|
|
258
196
|
desc "Display status of data migrations"
|
259
197
|
task :status => :environment do
|
260
|
-
|
261
|
-
ActiveRecord::Base.establish_connection(db_config)
|
262
|
-
DataMigrate::Tasks::DataMigrateTasks.status(db_config)
|
263
|
-
end
|
198
|
+
DataMigrate::Tasks::DataMigrateTasks.status
|
264
199
|
end
|
265
200
|
end
|
266
201
|
|
267
202
|
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
268
203
|
task :rollback => :environment do
|
269
|
-
DataMigrate::DataMigrator.
|
204
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
270
205
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
271
206
|
DataMigrate::DataMigrator.rollback(DataMigrate::DatabaseTasks.data_migrations_path, step)
|
272
207
|
Rake::Task["data:dump"].invoke
|
@@ -274,7 +209,7 @@ namespace :data do
|
|
274
209
|
|
275
210
|
desc 'Pushes the schema to the next version (specify steps w/ STEP=n).'
|
276
211
|
task :forward => :environment do
|
277
|
-
DataMigrate::DataMigrator.
|
212
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
278
213
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
279
214
|
# TODO: No worky for .forward
|
280
215
|
# DataMigrate::DataMigrator.forward('db/data/', step)
|
@@ -287,7 +222,7 @@ namespace :data do
|
|
287
222
|
|
288
223
|
desc "Retrieves the current schema version number for data migrations"
|
289
224
|
task :version => :environment do
|
290
|
-
DataMigrate::DataMigrator.
|
225
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
291
226
|
puts "Current data version: #{DataMigrate::DataMigrator.current_version}"
|
292
227
|
end
|
293
228
|
|
@@ -299,10 +234,7 @@ namespace :data do
|
|
299
234
|
|
300
235
|
desc "Create a db/data_schema.rb file that stores the current data version"
|
301
236
|
task dump: :environment do
|
302
|
-
|
303
|
-
ActiveRecord::Base.establish_connection(db_config)
|
304
|
-
DataMigrate::Tasks::DataMigrateTasks.dump(db_config)
|
305
|
-
end
|
237
|
+
DataMigrate::Tasks::DataMigrateTasks.dump
|
306
238
|
|
307
239
|
# Allow this task to be called as many times as required. An example
|
308
240
|
# is the migrate:redo task, which calls other two internally
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 11.0.0.rc
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew J Vargo
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-08-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -18,28 +18,28 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '6.
|
21
|
+
version: '6.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '6.
|
28
|
+
version: '6.1'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: railties
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '6.
|
35
|
+
version: '6.1'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '6.
|
42
|
+
version: '6.1'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: appraisal
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,16 +128,16 @@ dependencies:
|
|
128
128
|
name: sqlite3
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
|
-
- - "
|
131
|
+
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
133
|
+
version: '0'
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
|
-
- - "
|
138
|
+
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
|
-
version:
|
140
|
+
version: '0'
|
141
141
|
- !ruby/object:Gem::Dependency
|
142
142
|
name: timecop
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,14 +201,19 @@ files:
|
|
201
201
|
- Appraisals
|
202
202
|
- Changelog.md
|
203
203
|
- Gemfile
|
204
|
-
- Gemfile.
|
204
|
+
- Gemfile.lock
|
205
205
|
- LICENSE
|
206
206
|
- README.md
|
207
207
|
- Rakefile
|
208
208
|
- data_migrate.gemspec
|
209
|
-
- gemfiles/rails_6.0.gemfile
|
210
209
|
- gemfiles/rails_6.1.gemfile
|
210
|
+
- gemfiles/rails_6.1.gemfile.lock
|
211
211
|
- gemfiles/rails_7.0.gemfile
|
212
|
+
- gemfiles/rails_7.0.gemfile.lock
|
213
|
+
- gemfiles/rails_7.1.gemfile
|
214
|
+
- gemfiles/rails_7.1.gemfile.lock
|
215
|
+
- gemfiles/rails_7.2.gemfile
|
216
|
+
- gemfiles/rails_7.2.gemfile.lock
|
212
217
|
- lib/capistrano/data_migrate.rb
|
213
218
|
- lib/capistrano/data_migrate/migrate.rb
|
214
219
|
- lib/data_migrate.rb
|
@@ -216,14 +221,16 @@ files:
|
|
216
221
|
- lib/data_migrate/data_migrator.rb
|
217
222
|
- lib/data_migrate/data_schema.rb
|
218
223
|
- lib/data_migrate/data_schema_migration.rb
|
224
|
+
- lib/data_migrate/database_configurations_wrapper.rb
|
219
225
|
- lib/data_migrate/database_tasks.rb
|
220
|
-
- lib/data_migrate/legacy_migrator.rb
|
221
226
|
- lib/data_migrate/migration_context.rb
|
227
|
+
- lib/data_migrate/rails_helper.rb
|
222
228
|
- lib/data_migrate/railtie.rb
|
223
229
|
- lib/data_migrate/schema_dumper.rb
|
224
230
|
- lib/data_migrate/schema_migration.rb
|
225
231
|
- lib/data_migrate/status_service.rb
|
226
232
|
- lib/data_migrate/tasks/data_migrate_tasks.rb
|
233
|
+
- lib/data_migrate/test.rb
|
227
234
|
- lib/data_migrate/version.rb
|
228
235
|
- lib/generators/data_migrate.rb
|
229
236
|
- lib/generators/data_migration/data_migration_generator.rb
|
@@ -235,7 +242,6 @@ files:
|
|
235
242
|
- spec/data_migrate/data_schema_migration_spec.rb
|
236
243
|
- spec/data_migrate/data_spec.rb
|
237
244
|
- spec/data_migrate/database_tasks_spec.rb
|
238
|
-
- spec/data_migrate/legacy_migrator_spec.rb
|
239
245
|
- spec/data_migrate/migration.rb
|
240
246
|
- spec/data_migrate/migration_context_spec.rb
|
241
247
|
- spec/data_migrate/schema_dumper_spec.rb
|
@@ -274,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
274
280
|
- !ruby/object:Gem::Version
|
275
281
|
version: 1.3.1
|
276
282
|
requirements: []
|
277
|
-
rubygems_version: 3.
|
283
|
+
rubygems_version: 3.4.19
|
278
284
|
signing_key:
|
279
285
|
specification_version: 4
|
280
286
|
summary: Rake tasks to migrate data alongside schema changes.
|
data/Gemfile.rails6.1
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
module DataMigrate
|
2
|
-
class LegacyMigrator
|
3
|
-
def initialize(migrations_paths = "db/data")
|
4
|
-
@migrations_paths = migrations_paths || "db/data"
|
5
|
-
end
|
6
|
-
|
7
|
-
def migrate
|
8
|
-
dates =
|
9
|
-
DataMigrate::DataMigrator.migrations(@migrations_paths).collect(&:version)
|
10
|
-
legacy = ActiveRecord::SchemaMigration.where(version: dates)
|
11
|
-
legacy.each do |v|
|
12
|
-
begin
|
13
|
-
version = v.version
|
14
|
-
puts "Creating #{version} in data schema"
|
15
|
-
DataMigrate::DataSchemaMigration.create(version: version)
|
16
|
-
rescue ActiveRecord::RecordNotUnique
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe DataMigrate::LegacyMigrator do
|
6
|
-
let(:context) {
|
7
|
-
DataMigrate::MigrationContext.new("spec/db/data")
|
8
|
-
}
|
9
|
-
|
10
|
-
before do
|
11
|
-
ActiveRecord::SchemaMigration.create_table
|
12
|
-
DataMigrate::DataSchemaMigration.create_table
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
17
|
-
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
18
|
-
end
|
19
|
-
|
20
|
-
it "migrate legacy migrations to be in correct table" do
|
21
|
-
# simulate creation of legacy data migration when
|
22
|
-
# it was recorded in schema table
|
23
|
-
ActiveRecord::SchemaMigration.create(version: "20091231235959")
|
24
|
-
|
25
|
-
# create one migration in correct place
|
26
|
-
DataMigrate::DataSchemaMigration.create(version: "20171231235959")
|
27
|
-
|
28
|
-
migrated = DataMigrate::DataMigrator.new(:up, []).load_migrated
|
29
|
-
expect(migrated.count).to eq 1
|
30
|
-
|
31
|
-
DataMigrate::LegacyMigrator.new("spec/db/data").migrate
|
32
|
-
|
33
|
-
# after migacy migrator has been run, we should have records
|
34
|
-
# of both migrations
|
35
|
-
migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
|
36
|
-
expect(migrated.count).to eq 2
|
37
|
-
end
|
38
|
-
end
|