data_migrate 4.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +13 -1
- data/README.md +4 -0
- data/data_migrate.gemspec +4 -1
- data/lib/data_migrate.rb +10 -0
- data/lib/data_migrate/data_migrator.rb +4 -10
- data/lib/data_migrate/data_migrator_five.rb +1 -10
- data/lib/data_migrate/legacy_migrator.rb +22 -0
- data/lib/data_migrate/version.rb +1 -1
- data/lib/generators/data_migration/templates/data_migration.rb +1 -1
- data/spec/data_migrate/data_migrator_spec.rb +27 -1
- data/spec/data_migrate/legacy_migrator_spec.rb +50 -0
- data/spec/data_migrate/migration_context_spec.rb +19 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b86644bbbeb24eb00ad86756b55141264c1e4d5
|
4
|
+
data.tar.gz: 7a0e3820c6704f8fb4658366ebdd02b5b98283ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8116bd9c3b090995c161f1668a5dc20db9d977c2c4b2fdecbaa303dcf2551ad1fed477d93e6f9caa59a94b094e317f2c1cbda57fcc7ad16ccc576a50c1a2e759
|
7
|
+
data.tar.gz: f4a4bacd929dcbd8b23ffacfe142b0d4a59e5c51f441276a69227fef773d574eb2c84b948b934e43522451b7ddf78ed40af41e8b8085202db91a3b7d86e32f5e
|
data/Changelog.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
## 5.0.0
|
5
|
+
|
6
|
+
Remove support for legacy migrations (from v2).
|
7
|
+
|
8
|
+
**IMPORTANT**: If you used this gem from before version 2, make sure to run migration script
|
9
|
+
|
10
|
+
```
|
11
|
+
DataMigrate::LegacyMigrator.new.migrate
|
12
|
+
```
|
13
|
+
|
14
|
+
**Failure to do so may cause re-running old migrations**
|
15
|
+
|
4
16
|
## 4.0.0
|
5
17
|
|
6
18
|
Support for Rails 5.2
|
@@ -24,7 +36,7 @@ The concept of schema:dump to data migrations, thanks to
|
|
24
36
|
## 3.2.1
|
25
37
|
|
26
38
|
data_migrate table into rails schema dump, thanks to
|
27
|
-
[jturkel](https://github.com/jturkel)
|
39
|
+
[jturkel](https://github.com/jturkel)
|
28
40
|
|
29
41
|
|
30
42
|
## 3.2.0
|
data/README.md
CHANGED
@@ -80,6 +80,10 @@ the gem wrote data migration versions into
|
|
80
80
|
`schema_migrations` table. After the fix, it was corrected to write into
|
81
81
|
`data_migrations`.
|
82
82
|
|
83
|
+
If you need to use these old migrations, add the following configuration
|
84
|
+
|
85
|
+
It is recommended to move all legacy migrations from `schema_migrations` table into `data_migrations` table
|
86
|
+
|
83
87
|
This may cause some unintended consequences. See [#22](https://github.com/ilyakatz/data-migrate/issues/22)
|
84
88
|
|
85
89
|
#### v1
|
data/data_migrate.gemspec
CHANGED
@@ -35,7 +35,10 @@ Gem::Specification.new do |s|
|
|
35
35
|
|
36
36
|
s.post_install_message = <<-POST_INSTALL_MESSAGE
|
37
37
|
#{"*" * 80}
|
38
|
-
data-migrate:
|
38
|
+
data-migrate: IMPORTANT: Breaking change introduced for migrations from v2.
|
39
|
+
|
40
|
+
Failure to run the migration can have serious consequences.
|
41
|
+
See Readme for more info.
|
39
42
|
#{"*" * 80}
|
40
43
|
POST_INSTALL_MESSAGE
|
41
44
|
end
|
data/lib/data_migrate.rb
CHANGED
@@ -28,3 +28,13 @@ else
|
|
28
28
|
end
|
29
29
|
require File.join(File.dirname(__FILE__), "data_migrate", "railtie")
|
30
30
|
require File.join(File.dirname(__FILE__), "data_migrate", "tasks/data_migrate_tasks")
|
31
|
+
require File.join(File.dirname(__FILE__), "data_migrate", "legacy_migrator")
|
32
|
+
|
33
|
+
module DataMigrate
|
34
|
+
include ActiveSupport::Configurable
|
35
|
+
class << self
|
36
|
+
def configure
|
37
|
+
yield config
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -16,6 +16,9 @@ module DataMigrate
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def load_migrated(connection = ActiveRecord::Base.connection)
|
20
|
+
self.class.get_all_versions(connection)
|
21
|
+
end
|
19
22
|
|
20
23
|
class << self
|
21
24
|
def current_version(connection = ActiveRecord::Base.connection)
|
@@ -24,16 +27,7 @@ module DataMigrate
|
|
24
27
|
|
25
28
|
def get_all_versions(connection = ActiveRecord::Base.connection)
|
26
29
|
if table_exists?(connection, schema_migrations_table_name)
|
27
|
-
|
28
|
-
# schema_migrations table. After the fix, it was corrected to write into
|
29
|
-
# data_migrations. However, not to break anything we are going to
|
30
|
-
# get versions from both tables.
|
31
|
-
#
|
32
|
-
# This may cause some problems:
|
33
|
-
# Eg. rake data:versions will show version from the schema_migrations table
|
34
|
-
# which may be a version of actual schema migration and not data migration
|
35
|
-
DataMigrate::DataSchemaMigration.all.map { |x| x.version.to_i }.sort +
|
36
|
-
ActiveRecord::SchemaMigration.all.map { |x| x.version.to_i }.sort
|
30
|
+
DataMigrate::DataSchemaMigration.all.map { |x| x.version.to_i }.sort
|
37
31
|
else
|
38
32
|
[]
|
39
33
|
end
|
@@ -23,17 +23,8 @@ module DataMigrate
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def load_migrated
|
26
|
-
# Certain versions of the gem wrote data migration versions into
|
27
|
-
# schema_migrations table. After the fix, it was corrected to write into
|
28
|
-
# data_migrations. However, not to break anything we are going to
|
29
|
-
# get versions from both tables.
|
30
|
-
#
|
31
|
-
# This may cause some problems:
|
32
|
-
# Eg. rake data:versions will show version from the schema_migrations table
|
33
|
-
# which may be a version of actual schema migration and not data migration
|
34
26
|
@migrated_versions =
|
35
|
-
DataMigrate::DataSchemaMigration.normalized_versions.map(&:to_i).sort
|
36
|
-
ActiveRecord::SchemaMigration.normalized_versions.map(&:to_i).sort
|
27
|
+
DataMigrate::DataSchemaMigration.normalized_versions.map(&:to_i).sort
|
37
28
|
end
|
38
29
|
|
39
30
|
class << self
|
@@ -0,0 +1,22 @@
|
|
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
|
data/lib/data_migrate/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe DataMigrate::DataMigrator do
|
4
4
|
let(:subject) { DataMigrate::DataMigrator }
|
@@ -9,6 +9,32 @@ describe DataMigrate::DataMigrator do
|
|
9
9
|
}
|
10
10
|
end
|
11
11
|
|
12
|
+
describe :load_migrated do
|
13
|
+
before do
|
14
|
+
allow(subject).to receive(:db_config) { db_config }.at_least(:once)
|
15
|
+
ActiveRecord::Base.establish_connection(db_config)
|
16
|
+
::ActiveRecord::SchemaMigration.create_table
|
17
|
+
DataMigrate::DataSchemaMigration.create_table
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
ActiveRecord::Migration.drop_table("data_migrations")
|
22
|
+
ActiveRecord::Migration.drop_table("schema_migrations")
|
23
|
+
end
|
24
|
+
|
25
|
+
it do
|
26
|
+
subject.assure_data_schema_table
|
27
|
+
DataMigrate::DataSchemaMigration.create(version: 20090000000000)
|
28
|
+
::ActiveRecord::SchemaMigration.create(version: 20100000000000)
|
29
|
+
DataMigrate::DataSchemaMigration.create(version: 20110000000000)
|
30
|
+
::ActiveRecord::SchemaMigration.create(version: 20120000000000)
|
31
|
+
migrated = subject.new(:up, []).load_migrated
|
32
|
+
expect(migrated.count).to eq 2
|
33
|
+
expect(migrated).to include 20090000000000
|
34
|
+
expect(migrated).to include 20110000000000
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
12
38
|
describe :assure_data_schema_table do
|
13
39
|
before do
|
14
40
|
allow(subject).to receive(:db_config) { db_config }.at_least(:once)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DataMigrate::LegacyMigrator do
|
4
|
+
let(:context) {
|
5
|
+
DataMigrate::MigrationContext.new("spec/db/data")
|
6
|
+
}
|
7
|
+
|
8
|
+
after do
|
9
|
+
begin
|
10
|
+
ActiveRecord::Migration.drop_table("data_migrations")
|
11
|
+
ActiveRecord::Migration.drop_table("schema_migrations")
|
12
|
+
rescue StandardError
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
ActiveRecord::Base.establish_connection(db_config)
|
19
|
+
ActiveRecord::SchemaMigration.create_table
|
20
|
+
DataMigrate::DataSchemaMigration.create_table
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:db_config) do
|
24
|
+
{
|
25
|
+
adapter: "sqlite3",
|
26
|
+
database: "spec/db/test.db"
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
it "migrate legacy migrations to be in correct table" do
|
31
|
+
DataMigrate::DataSchemaMigration.create_table
|
32
|
+
# simulate creation of legacy data migration when
|
33
|
+
# it was recorded in schema table
|
34
|
+
ActiveRecord::SchemaMigration.create(version: "20091231235959")
|
35
|
+
|
36
|
+
# create one migration in correct place
|
37
|
+
DataMigrate::DataSchemaMigration.create(version: "20171231235959")
|
38
|
+
|
39
|
+
migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
|
40
|
+
expect(migrated.count).to eq 1
|
41
|
+
|
42
|
+
DataMigrate::LegacyMigrator.new("spec/db/data").migrate
|
43
|
+
|
44
|
+
# after migacy migrator has been run, we should have records
|
45
|
+
# of both migrations
|
46
|
+
migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
|
47
|
+
expect(migrated.count).to eq 2
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -4,6 +4,9 @@ describe DataMigrate::DataMigrator do
|
|
4
4
|
let(:context) {
|
5
5
|
DataMigrate::MigrationContext.new("spec/db/data")
|
6
6
|
}
|
7
|
+
let(:schema_context) {
|
8
|
+
ActiveRecord::MigrationContext.new("spec/db/migrate/5.2")
|
9
|
+
}
|
7
10
|
|
8
11
|
before do
|
9
12
|
unless Rails::VERSION::MAJOR == 5 and
|
@@ -15,6 +18,7 @@ describe DataMigrate::DataMigrator do
|
|
15
18
|
after do
|
16
19
|
begin
|
17
20
|
ActiveRecord::Migration.drop_table("data_migrations")
|
21
|
+
ActiveRecord::Migration.drop_table("schema_migrations")
|
18
22
|
rescue StandardError
|
19
23
|
nil
|
20
24
|
end
|
@@ -33,6 +37,11 @@ describe DataMigrate::DataMigrator do
|
|
33
37
|
ActiveRecord::SchemaMigration.create_table
|
34
38
|
end
|
35
39
|
|
40
|
+
after do
|
41
|
+
ActiveRecord::Migration.drop_table("data_migrations")
|
42
|
+
ActiveRecord::Migration.drop_table("schema_migrations")
|
43
|
+
end
|
44
|
+
|
36
45
|
it "migrates existing file" do
|
37
46
|
context.migrate(nil)
|
38
47
|
context.migrations_status
|
@@ -95,6 +104,16 @@ describe DataMigrate::DataMigrator do
|
|
95
104
|
expect(versions).to include("20091231235959")
|
96
105
|
end
|
97
106
|
|
107
|
+
it "rolls back 2 migrations" do
|
108
|
+
context.migrate(nil)
|
109
|
+
schema_context.migrate(nil)
|
110
|
+
expect {
|
111
|
+
context.rollback(2)
|
112
|
+
}.to output(/Undoing SomeName/).to_stdout
|
113
|
+
versions = DataMigrate::DataSchemaMigration.normalized_versions
|
114
|
+
expect(versions.count).to eq(0)
|
115
|
+
end
|
116
|
+
|
98
117
|
it "rolls back 2 migrations" do
|
99
118
|
context.migrate(nil)
|
100
119
|
expect {
|
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: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew J Vargo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- lib/data_migrate/data_schema.rb
|
204
204
|
- lib/data_migrate/data_schema_migration.rb
|
205
205
|
- lib/data_migrate/database_tasks.rb
|
206
|
+
- lib/data_migrate/legacy_migrator.rb
|
206
207
|
- lib/data_migrate/migration.rb
|
207
208
|
- lib/data_migrate/migration_context.rb
|
208
209
|
- lib/data_migrate/migration_five.rb
|
@@ -223,6 +224,7 @@ files:
|
|
223
224
|
- spec/data_migrate/data_schema_migration_spec.rb
|
224
225
|
- spec/data_migrate/data_spec.rb
|
225
226
|
- spec/data_migrate/database_tasks_spec.rb
|
227
|
+
- spec/data_migrate/legacy_migrator_spec.rb
|
226
228
|
- spec/data_migrate/migration.rb
|
227
229
|
- spec/data_migrate/migration_context_spec.rb
|
228
230
|
- spec/data_migrate/schema_dumper_spec.rb
|
@@ -251,7 +253,10 @@ licenses:
|
|
251
253
|
metadata: {}
|
252
254
|
post_install_message: |
|
253
255
|
********************************************************************************
|
254
|
-
data-migrate:
|
256
|
+
data-migrate: IMPORTANT: Breaking change introduced for migrations from v2.
|
257
|
+
|
258
|
+
Failure to run the migration can have serious consequences.
|
259
|
+
See Readme for more info.
|
255
260
|
********************************************************************************
|
256
261
|
rdoc_options: []
|
257
262
|
require_paths:
|
@@ -277,6 +282,7 @@ test_files:
|
|
277
282
|
- spec/data_migrate/data_schema_migration_spec.rb
|
278
283
|
- spec/data_migrate/data_spec.rb
|
279
284
|
- spec/data_migrate/database_tasks_spec.rb
|
285
|
+
- spec/data_migrate/legacy_migrator_spec.rb
|
280
286
|
- spec/data_migrate/migration.rb
|
281
287
|
- spec/data_migrate/migration_context_spec.rb
|
282
288
|
- spec/data_migrate/schema_dumper_spec.rb
|