data_migrate 1.2.0 → 2.0.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 +7 -0
- data/README.md +18 -3
- data/data_migrate.gemspec +4 -3
- data/lib/data_migrate.rb +2 -0
- data/lib/data_migrate/data_migrator.rb +29 -0
- data/lib/data_migrate/data_schema_migration.rb +14 -0
- data/lib/data_migrate/migration.rb +28 -0
- data/lib/data_migrate/version.rb +1 -1
- data/lib/generators/data_migration/templates/data_migration.rb +1 -1
- data/tasks/databases.rake +1 -1
- metadata +18 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 23e116644d7dd0d7284d7b947531ba6c458dc1eb
|
4
|
+
data.tar.gz: 6122e7766a889e121f3089b9f34e9971e240bdcf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6596304649605db5edeaf00d0a15f9d2e9c1259c3aed3e0c45f9a76e0414a9c6e5282904a42863573455e12abe3da46afeb8fdccaeef3aa97309a59d8f199412
|
7
|
+
data.tar.gz: a0c1d3c00a95216f872cacfa8662263816a5261e6e5624802b054cd28f40a473e47a3f8af955ae3731a2c7f0b86bffba736a4a4ef0e921cf9fba37c83dc2051e
|
data/README.md
CHANGED
@@ -68,10 +68,23 @@ schema and data migrations in the proper order.
|
|
68
68
|
|
69
69
|
Note: If a data and schema migration share the same version number, schema gets precedence when migrating up. Data does down.
|
70
70
|
|
71
|
-
Rails
|
71
|
+
Rails Support
|
72
72
|
--------------------
|
73
73
|
|
74
|
-
|
74
|
+
Rails 3.1: Version 1.2 supports Rails 3.1.0 and higher **but** is not longer maintained.
|
75
|
+
|
76
|
+
Rails 4: Version 2.0 supports Rails 4.0 and higher
|
77
|
+
|
78
|
+
Rails 5: Not tested
|
79
|
+
|
80
|
+
### Important note
|
81
|
+
|
82
|
+
If you upgraded to Rails 4 while using `data_migrate` prior to version 2,
|
83
|
+
the gem wrote data migration versions into
|
84
|
+
`schema_migrations` table. After the fix, it was corrected to write into
|
85
|
+
`data_migrations`.
|
86
|
+
|
87
|
+
This may cause some unintended consequences. See [#22](https://github.com/ilyakatz/data-migrate/issues/22)
|
75
88
|
|
76
89
|
Installation
|
77
90
|
------------
|
@@ -106,7 +119,6 @@ If you need a data only migration, either run it as such, with the skip-schema-m
|
|
106
119
|
|
107
120
|
rails g data_migration add_this_to_that --skip-schema-migration
|
108
121
|
|
109
|
-
|
110
122
|
### Rake Tasks
|
111
123
|
|
112
124
|
$> rake -T data
|
@@ -144,5 +156,8 @@ Going down instead of up would be the opposite.
|
|
144
156
|
|
145
157
|
Thanks
|
146
158
|
------
|
159
|
+
[Andrew J Vargo](http://github.com/ajvargo) Andrew was the original creator and maintainer of this project!
|
160
|
+
|
147
161
|
[Jeremy Durham](http://jeremydurham.com/) for fleshing out the idea with me, and providing guidance.
|
162
|
+
|
148
163
|
You! Yes, you. Thanks for checking it out.
|
data/data_migrate.gemspec
CHANGED
@@ -6,15 +6,16 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "data_migrate"
|
7
7
|
s.version = DataMigrate::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Andrew J Vargo"]
|
10
|
-
s.email = ["ajvargo@computer.org"]
|
9
|
+
s.authors = ["Andrew J Vargo", "Ilya Katz"]
|
10
|
+
s.email = ["ajvargo@computer.org", "ilyakatz@gmail.com"]
|
11
11
|
s.homepage = "http://ajvargo.com"
|
12
12
|
s.summary = %q{Rake tasks to migrate data alongside schema changes.}
|
13
13
|
s.description = %q{Rake tasks to migrate data alongside schema changes.}
|
14
|
+
s.license = "MIT"
|
14
15
|
|
15
16
|
s.rubyforge_project = "data_migrate"
|
16
17
|
|
17
|
-
s.add_dependency('rails', '>=
|
18
|
+
s.add_dependency('rails', '>= 4.0')
|
18
19
|
|
19
20
|
s.files = `git ls-files`.split("\n")
|
20
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/data_migrate.rb
CHANGED
@@ -1,2 +1,4 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'data_migrate', 'data_migrator')
|
2
|
+
require File.join(File.dirname(__FILE__), 'data_migrate', 'data_schema_migration')
|
3
|
+
require File.join(File.dirname(__FILE__), 'data_migrate', 'migration')
|
2
4
|
require File.join(File.dirname(__FILE__), 'data_migrate', 'railtie')
|
@@ -1,8 +1,37 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
3
|
module DataMigrate
|
4
|
+
|
4
5
|
class DataMigrator < ActiveRecord::Migrator
|
6
|
+
|
7
|
+
def record_version_state_after_migrating(version)
|
8
|
+
if down?
|
9
|
+
migrated.delete(version)
|
10
|
+
DataMigrate::DataSchemaMigration.where(:version => version.to_s).delete_all
|
11
|
+
else
|
12
|
+
migrated << version
|
13
|
+
DataMigrate::DataSchemaMigration.create!(:version => version.to_s)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
5
17
|
class << self
|
18
|
+
def get_all_versions(connection = ActiveRecord::Base.connection)
|
19
|
+
if connection.table_exists?(schema_migrations_table_name)
|
20
|
+
# Certain versions of the gem wrote data migration versions into
|
21
|
+
# schema_migrations table. After the fix, it was corrected to write into
|
22
|
+
# data_migrations. However, not to break anything we are going to
|
23
|
+
# get versions from both tables.
|
24
|
+
#
|
25
|
+
# This may cause some problems:
|
26
|
+
# Eg. rake data:versions will show version from the schema_migrations table
|
27
|
+
# which may be a version of actual schema migration and not data migration
|
28
|
+
DataMigrate::DataSchemaMigration.all.map { |x| x.version.to_i }.sort +
|
29
|
+
ActiveRecord::SchemaMigration.all.map { |x| x.version.to_i }.sort
|
30
|
+
else
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
6
35
|
def schema_migrations_table_name
|
7
36
|
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
|
8
37
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DataMigrate
|
2
|
+
class DataSchemaMigration < ::ActiveRecord::SchemaMigration
|
3
|
+
class << self
|
4
|
+
def table_name
|
5
|
+
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
|
6
|
+
end
|
7
|
+
|
8
|
+
def index_name
|
9
|
+
"#{table_name_prefix}unique_data_migrations#{table_name_suffix}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module DataMigrate
|
2
|
+
class Migration < ::ActiveRecord::Migration
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def check_pending!(connection = ::ActiveRecord::Base.connection)
|
6
|
+
binding.pry
|
7
|
+
raise ActiveRecord::PendingMigrationError if DataMigrator::Migrator.needs_migration?(connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
def migrate(direction)
|
11
|
+
new.migrate direction
|
12
|
+
end
|
13
|
+
|
14
|
+
def table_name
|
15
|
+
binding.pry
|
16
|
+
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
|
17
|
+
end
|
18
|
+
|
19
|
+
def index_name
|
20
|
+
"#{table_name_prefix}unique_data_migrations#{table_name_suffix}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(name = self.class.name, version = nil)
|
25
|
+
super(name, version)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/data_migrate/version.rb
CHANGED
data/tasks/databases.rake
CHANGED
@@ -217,7 +217,7 @@ namespace :data do
|
|
217
217
|
desc 'Migrate data migrations (options: VERSION=x, VERBOSE=false)'
|
218
218
|
task :migrate => :environment do
|
219
219
|
assure_data_schema_table
|
220
|
-
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
220
|
+
#ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
221
221
|
DataMigrate::DataMigrator.migrate("db/data/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
222
222
|
end
|
223
223
|
|
metadata
CHANGED
@@ -1,40 +1,39 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Andrew J Vargo
|
8
|
+
- Ilya Katz
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
17
|
requirements:
|
19
|
-
- -
|
18
|
+
- - ">="
|
20
19
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
20
|
+
version: '4.0'
|
22
21
|
type: :runtime
|
23
22
|
prerelease: false
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
|
-
- -
|
25
|
+
- - ">="
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
27
|
+
version: '4.0'
|
30
28
|
description: Rake tasks to migrate data alongside schema changes.
|
31
29
|
email:
|
32
30
|
- ajvargo@computer.org
|
31
|
+
- ilyakatz@gmail.com
|
33
32
|
executables: []
|
34
33
|
extensions: []
|
35
34
|
extra_rdoc_files: []
|
36
35
|
files:
|
37
|
-
- .gitignore
|
36
|
+
- ".gitignore"
|
38
37
|
- Gemfile
|
39
38
|
- LICENSE
|
40
39
|
- README.md
|
@@ -42,6 +41,8 @@ files:
|
|
42
41
|
- data_migrate.gemspec
|
43
42
|
- lib/data_migrate.rb
|
44
43
|
- lib/data_migrate/data_migrator.rb
|
44
|
+
- lib/data_migrate/data_schema_migration.rb
|
45
|
+
- lib/data_migrate/migration.rb
|
45
46
|
- lib/data_migrate/railtie.rb
|
46
47
|
- lib/data_migrate/version.rb
|
47
48
|
- lib/generators/data_migrate.rb
|
@@ -51,27 +52,27 @@ files:
|
|
51
52
|
- tasks/.gitkeep
|
52
53
|
- tasks/databases.rake
|
53
54
|
homepage: http://ajvargo.com
|
54
|
-
licenses:
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
55
58
|
post_install_message:
|
56
59
|
rdoc_options: []
|
57
60
|
require_paths:
|
58
61
|
- lib
|
59
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
63
|
requirements:
|
62
|
-
- -
|
64
|
+
- - ">="
|
63
65
|
- !ruby/object:Gem::Version
|
64
66
|
version: '0'
|
65
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
68
|
requirements:
|
68
|
-
- -
|
69
|
+
- - ">="
|
69
70
|
- !ruby/object:Gem::Version
|
70
71
|
version: '0'
|
71
72
|
requirements: []
|
72
73
|
rubyforge_project: data_migrate
|
73
|
-
rubygems_version:
|
74
|
+
rubygems_version: 2.4.8
|
74
75
|
signing_key:
|
75
|
-
specification_version:
|
76
|
+
specification_version: 4
|
76
77
|
summary: Rake tasks to migrate data alongside schema changes.
|
77
78
|
test_files: []
|