data_migrate 2.0.1 → 2.1.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/.gitignore +1 -0
- data/Changelog.md +7 -0
- data/lib/data_migrate/data_migrator.rb +21 -0
- data/lib/data_migrate/version.rb +1 -1
- data/tasks/databases.rake +14 -13
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a61a9b037890457c24cc8cea7276360ae1fd56c
|
4
|
+
data.tar.gz: f5f4fd95f631b962accb8c1709967ada6a771d22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71d3e595a3ecc3e49b9509b6ae6250394c89514900d35b992480a609527d0a7413940c3ba06b274f74f5968d53a6b77bcf362c839e27c8f60d1352ff92c346a5
|
7
|
+
data.tar.gz: b98a1f2a4ab114da88312dbfb56ef1710ecdc3aebf61c2f68d10240daa95eadafad8aa688611d3011aa32682134082635b2d78437bf6db091e5ececd72670c88
|
data/.gitignore
CHANGED
data/Changelog.md
ADDED
@@ -39,6 +39,27 @@ module DataMigrate
|
|
39
39
|
def migrations_path
|
40
40
|
'db/data'
|
41
41
|
end
|
42
|
+
|
43
|
+
def assure_data_schema_table
|
44
|
+
config = ActiveRecord::Base.configurations[Rails.env || 'development'] || ENV["DATABASE_URL"]
|
45
|
+
ActiveRecord::Base.establish_connection(config)
|
46
|
+
sm_table = DataMigrate::DataMigrator.schema_migrations_table_name
|
47
|
+
|
48
|
+
unless ActiveRecord::Base.connection.table_exists?(sm_table)
|
49
|
+
ActiveRecord::Base.connection.create_table(sm_table, :id => false) do |schema_migrations_table|
|
50
|
+
schema_migrations_table.column :version, :string, :null => false
|
51
|
+
end
|
52
|
+
|
53
|
+
suffix = ActiveRecord::Base.table_name_suffix
|
54
|
+
prefix = ActiveRecord::Base.table_name_prefix
|
55
|
+
index_name = "#{prefix}unique_data_migrations#{suffix}"
|
56
|
+
|
57
|
+
ActiveRecord::Base.connection.add_index sm_table, :version,
|
58
|
+
:unique => true,
|
59
|
+
:name => index_name
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
42
63
|
end
|
43
64
|
end
|
44
65
|
end
|
data/lib/data_migrate/version.rb
CHANGED
data/tasks/databases.rake
CHANGED
@@ -49,7 +49,11 @@ namespace :db do
|
|
49
49
|
DataMigrate::DataMigrator.run(migration[:direction], "db/data/", migration[:version])
|
50
50
|
else
|
51
51
|
ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
|
52
|
-
ActiveRecord::Migrator.run(
|
52
|
+
ActiveRecord::Migrator.run(
|
53
|
+
migration[:direction],
|
54
|
+
Rails.application.config.paths["db/migrate"],
|
55
|
+
migration[:version]
|
56
|
+
)
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
@@ -312,11 +316,17 @@ def pending_migrations
|
|
312
316
|
end
|
313
317
|
|
314
318
|
def pending_data_migrations
|
315
|
-
|
319
|
+
data_migrations = DataMigrate::DataMigrator.migrations('db/data')
|
320
|
+
sort_migrations DataMigrate::DataMigrator.new(:up, data_migrations ).
|
321
|
+
pending_migrations.map{|m| { :version => m.version, :kind => :data }}
|
316
322
|
end
|
317
323
|
|
318
324
|
def pending_schema_migrations
|
319
|
-
|
325
|
+
all_migrations = ActiveRecord::Migrator.migrations(Rails.application.config.paths["db/migrate"])
|
326
|
+
sort_migrations(
|
327
|
+
ActiveRecord::Migrator.new(:up, all_migrations).
|
328
|
+
pending_migrations.
|
329
|
+
map{|m| { :version => m.version, :kind => :schema }})
|
320
330
|
end
|
321
331
|
|
322
332
|
def sort_migrations set_1, set_2=nil
|
@@ -353,14 +363,5 @@ def past_migrations sort=nil
|
|
353
363
|
end
|
354
364
|
|
355
365
|
def assure_data_schema_table
|
356
|
-
|
357
|
-
ActiveRecord::Base.establish_connection(config)
|
358
|
-
sm_table = DataMigrate::DataMigrator.schema_migrations_table_name
|
359
|
-
|
360
|
-
unless ActiveRecord::Base.connection.table_exists?(sm_table)
|
361
|
-
ActiveRecord::Base.connection.create_table(sm_table, :id => false) do |schema_migrations_table|
|
362
|
-
schema_migrations_table.column :version, :string, :null => false
|
363
|
-
end
|
364
|
-
ActiveRecord::Base.connection.add_index sm_table, :version, :unique => true, :name => "#{ActiveRecord::Base.table_name_prefix}unique_data_migrations#{ActiveRecord::Base.table_name_suffix}"
|
365
|
-
end
|
366
|
+
DataMigrate::DataMigrator.assure_data_schema_table
|
366
367
|
end
|
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: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew J Vargo
|
@@ -9,20 +9,20 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-03-
|
12
|
+
date: 2016-03-28 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
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '4.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '4.0'
|
28
28
|
description: Rake tasks to migrate data alongside schema changes.
|
@@ -33,7 +33,8 @@ executables: []
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
-
-
|
36
|
+
- .gitignore
|
37
|
+
- Changelog.md
|
37
38
|
- Gemfile
|
38
39
|
- LICENSE
|
39
40
|
- README.md
|
@@ -61,17 +62,17 @@ require_paths:
|
|
61
62
|
- lib
|
62
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
64
|
requirements:
|
64
|
-
- -
|
65
|
+
- - '>='
|
65
66
|
- !ruby/object:Gem::Version
|
66
67
|
version: '0'
|
67
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
69
|
requirements:
|
69
|
-
- -
|
70
|
+
- - '>='
|
70
71
|
- !ruby/object:Gem::Version
|
71
72
|
version: '0'
|
72
73
|
requirements: []
|
73
74
|
rubyforge_project: data_migrate
|
74
|
-
rubygems_version: 2.
|
75
|
+
rubygems_version: 2.0.14.1
|
75
76
|
signing_key:
|
76
77
|
specification_version: 4
|
77
78
|
summary: Rake tasks to migrate data alongside schema changes.
|