data_migrator 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/data_migrator.rb +32 -25
- data/lib/data_migrator/version.rb +3 -3
- data/lib/tasks/data_migrator.rake +18 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac1182988cd87a3abf3a2a8ac483790e458809ae
|
4
|
+
data.tar.gz: f123784895f973a10cbe187627e41a923bb316dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2b440527b64f4e41c73c0948b9ac3154acaf93dc6e860d21490f15064b8322a13f3f6ef05e107e269f754ca61929aa496fb141a8864cd2ebf941653330d6ecb
|
7
|
+
data.tar.gz: d85dc76088913b6ce36ecab33f2c47de741b83b62c6e1852b4e3f6ed0c237e1c0900f707defebffe32cd9e2885ef83f72d8bcc73cbe803e59fb8f3156ef0f974
|
data/lib/data_migrator.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require "benchmark"
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "extensions/railties/engine"
|
3
|
+
require "extensions/railties/engine/configuration"
|
4
4
|
|
5
5
|
class DataMigrationTask < Rails::Railtie
|
6
6
|
rake_tasks do
|
7
|
-
Dir[File.join(File.dirname(__FILE__),
|
7
|
+
Dir[File.join(File.dirname(__FILE__), "tasks/*.rake")].each { |f| load f }
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -18,7 +18,7 @@ module RussellEdge
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def migrations(path)
|
21
|
-
files = Dir["#{path}/**/[0-9]*_*.rb"
|
21
|
+
files = Dir["#{path}/**/[0-9]*_*.rb"]
|
22
22
|
|
23
23
|
seen = Hash.new false
|
24
24
|
|
@@ -37,7 +37,7 @@ module RussellEdge
|
|
37
37
|
{:name => name, :filename => file, :version => version, :scope => scope}
|
38
38
|
end
|
39
39
|
|
40
|
-
migrations.sort_by{|h| h[:version]}
|
40
|
+
migrations.sort_by { |h| h[:version] }
|
41
41
|
end
|
42
42
|
|
43
43
|
def next_migration_number(number)
|
@@ -46,7 +46,7 @@ module RussellEdge
|
|
46
46
|
|
47
47
|
def initialize_data_migrations_table
|
48
48
|
puts "** data_migrations table missing creating now...."
|
49
|
-
puts ActiveRecord::Migrator.run(:up, File.join(File.dirname(__FILE__),
|
49
|
+
puts ActiveRecord::Migrator.run(:up, File.join(File.dirname(__FILE__), "../db/migrate/"), 20100819181805)
|
50
50
|
puts "** done"
|
51
51
|
end
|
52
52
|
|
@@ -64,7 +64,7 @@ module RussellEdge
|
|
64
64
|
|
65
65
|
if duplicate = destination_migrations.detect { |m| m[:name] == migration[:name] }
|
66
66
|
if options[:refresh] && duplicate[:scope] == scope.to_s
|
67
|
-
Dir.glob(File.join(destination,"*_#{migration[:name].underscore}.#{scope.to_s}.rb")).each { |f| puts "Removing old migration #{migration[:name]}"; File.delete(f) }
|
67
|
+
Dir.glob(File.join(destination, "*_#{migration[:name].underscore}.#{scope.to_s}.rb")).each { |f| puts "Removing old migration #{migration[:name]}"; File.delete(f) }
|
68
68
|
elsif options[:on_skip] && duplicate[:scope] != scope.to_s
|
69
69
|
options[:on_skip].call(scope, migration)
|
70
70
|
end
|
@@ -85,14 +85,13 @@ module RussellEdge
|
|
85
85
|
|
86
86
|
copied
|
87
87
|
end
|
88
|
-
|
89
88
|
end
|
90
89
|
|
91
|
-
def initialize(migrations_path=nil)
|
90
|
+
def initialize(migrations_path = nil)
|
92
91
|
@default_migrations_path = migrations_path || "#{Rails.root}/db/data_migrations"
|
93
92
|
end
|
94
93
|
|
95
|
-
def migrate(passed_location=nil, passed_version=nil)
|
94
|
+
def migrate(passed_location = nil, passed_version = nil)
|
96
95
|
setup
|
97
96
|
|
98
97
|
location = passed_location.nil? ? @default_migrations_path : passed_location
|
@@ -121,13 +120,27 @@ module RussellEdge
|
|
121
120
|
def get_current_version
|
122
121
|
result = ActiveRecord::Base.connection.select_all("select max(version) as current_version from data_migrations")
|
123
122
|
|
124
|
-
current_version = result[0][
|
123
|
+
current_version = result[0]["current_version"] unless result == -1
|
125
124
|
|
126
125
|
current_version = current_version.to_i unless current_version.nil?
|
127
126
|
|
128
127
|
current_version
|
129
128
|
end
|
130
129
|
|
130
|
+
def run_up_without_migration
|
131
|
+
versions = []
|
132
|
+
files = get_all_files
|
133
|
+
files.each do |file|
|
134
|
+
filename, version, klass_name = separate_file_parts(file)
|
135
|
+
unless version_has_been_migrated?(version)
|
136
|
+
insert_migration_version(version)
|
137
|
+
versions << version
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
versions
|
142
|
+
end
|
143
|
+
|
131
144
|
def run_up(passed_version)
|
132
145
|
setup
|
133
146
|
|
@@ -145,7 +158,6 @@ module RussellEdge
|
|
145
158
|
end
|
146
159
|
|
147
160
|
puts "** Version #{passed_version} not found" unless found
|
148
|
-
|
149
161
|
end
|
150
162
|
|
151
163
|
def run_down(passed_version)
|
@@ -165,7 +177,6 @@ module RussellEdge
|
|
165
177
|
end
|
166
178
|
|
167
179
|
puts "** Version #{passed_version} not found" unless found
|
168
|
-
|
169
180
|
end
|
170
181
|
|
171
182
|
private
|
@@ -176,7 +187,7 @@ module RussellEdge
|
|
176
187
|
unless File.directory? @default_migrations_path
|
177
188
|
FileUtils.mkdir_p(@default_migrations_path)
|
178
189
|
#create ignore folder
|
179
|
-
FileUtils.mkdir_p(File.join(@default_migrations_path,
|
190
|
+
FileUtils.mkdir_p(File.join(@default_migrations_path, "ignore/"))
|
180
191
|
end
|
181
192
|
end
|
182
193
|
|
@@ -191,7 +202,6 @@ module RussellEdge
|
|
191
202
|
end
|
192
203
|
end
|
193
204
|
end
|
194
|
-
|
195
205
|
end
|
196
206
|
|
197
207
|
def run_all_non_migrated(passed_version)
|
@@ -216,7 +226,6 @@ module RussellEdge
|
|
216
226
|
handle_action(file, klass_name, version, :down) if version_has_been_migrated?(version)
|
217
227
|
end
|
218
228
|
end
|
219
|
-
|
220
229
|
end
|
221
230
|
|
222
231
|
def handle_action(file, klass_name, version, action)
|
@@ -251,7 +260,7 @@ module RussellEdge
|
|
251
260
|
|
252
261
|
db_result = ActiveRecord::Base.connection.select_all("select count(*) as num_rows from data_migrations where version = '#{version}'")
|
253
262
|
|
254
|
-
num_rows = db_result[0][
|
263
|
+
num_rows = db_result[0]["num_rows"] unless db_result == -1
|
255
264
|
|
256
265
|
result = false if (num_rows.nil? || num_rows.to_i == 0)
|
257
266
|
result
|
@@ -259,15 +268,15 @@ module RussellEdge
|
|
259
268
|
|
260
269
|
def data_migrations_table_exists?
|
261
270
|
table_names = ActiveRecord::Base.connection.tables
|
262
|
-
table_names.include?(
|
271
|
+
table_names.include?("data_migrations")
|
263
272
|
end
|
264
273
|
|
265
274
|
def separate_file_parts(file)
|
266
|
-
paths = file.split(
|
275
|
+
paths = file.split("/")
|
267
276
|
filename = paths[paths.length - 1]
|
268
|
-
version = filename.split(
|
277
|
+
version = filename.split("_")[0]
|
269
278
|
klass_name = filename.gsub(/#{version}/, "").gsub(/\.rb/, "")[1..filename.length]
|
270
|
-
klass_name = klass_name.split(
|
279
|
+
klass_name = klass_name.split(".")[0] if klass_name.split(".").length > 1 #check for scope of engine name
|
271
280
|
|
272
281
|
return filename, version.to_i, klass_name
|
273
282
|
end
|
@@ -276,12 +285,10 @@ module RussellEdge
|
|
276
285
|
files = []
|
277
286
|
|
278
287
|
if File.directory? @default_migrations_path
|
279
|
-
|
280
288
|
files_or_directories = Dir.entries(@default_migrations_path).map { |directory| directory }
|
281
289
|
|
282
290
|
files_or_directories.delete_if { |name| name =~ REMOVE_FILES_REGEX } #remove any file leading with . or ..
|
283
|
-
files_or_directories.delete_if { |name| name ==
|
284
|
-
|
291
|
+
files_or_directories.delete_if { |name| name == "ignore" } #ignore the ignore folder
|
285
292
|
|
286
293
|
files_or_directories.each do |file_or_directory|
|
287
294
|
file_or_directory = @default_migrations_path + "/" + file_or_directory
|
@@ -299,7 +306,7 @@ module RussellEdge
|
|
299
306
|
files_or_directories = Dir.entries(file_or_directory).map { |directory| directory }
|
300
307
|
|
301
308
|
files_or_directories.delete_if { |name| name =~ REMOVE_FILES_REGEX } #remove any file leading with . or ..
|
302
|
-
files_or_directories.delete_if { |name| name ==
|
309
|
+
files_or_directories.delete_if { |name| name == "ignore" } #ignore the ignore folder
|
303
310
|
|
304
311
|
files_or_directories.each do |_file_or_directory|
|
305
312
|
_file_or_directory = file_or_directory + "/" + _file_or_directory
|
@@ -1,5 +1,5 @@
|
|
1
1
|
namespace :db do
|
2
|
-
desc
|
2
|
+
desc "migrates data into database"
|
3
3
|
task :migrate_data => :environment do
|
4
4
|
passed_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
5
5
|
|
@@ -7,7 +7,7 @@ namespace :db do
|
|
7
7
|
|
8
8
|
Rake::Task["db:schema:dump"].reenable
|
9
9
|
Rake::Task["db:schema:dump"].invoke
|
10
|
-
end#end migrate_data task
|
10
|
+
end #end migrate_data task
|
11
11
|
|
12
12
|
namespace :migrate_data do
|
13
13
|
task :list_pending => :environment do
|
@@ -15,12 +15,12 @@ namespace :db do
|
|
15
15
|
puts "================Pending Data Migrations=========="
|
16
16
|
puts pending_migrations
|
17
17
|
puts "================================================="
|
18
|
-
end#end list_pending task
|
18
|
+
end #end list_pending task
|
19
19
|
|
20
20
|
task :version => :environment do
|
21
21
|
version = RussellEdge::DataMigrator.new.get_current_version
|
22
22
|
puts (version.nil?) ? "** No migrations ran" : "** Current version #{version}"
|
23
|
-
end#end version task
|
23
|
+
end #end version task
|
24
24
|
|
25
25
|
task :up => :environment do
|
26
26
|
passed_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
@@ -30,7 +30,7 @@ namespace :db do
|
|
30
30
|
|
31
31
|
Rake::Task["db:schema:dump"].reenable
|
32
32
|
Rake::Task["db:schema:dump"].invoke
|
33
|
-
end#end up task
|
33
|
+
end #end up task
|
34
34
|
|
35
35
|
task :down => :environment do
|
36
36
|
passed_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
@@ -40,24 +40,31 @@ namespace :db do
|
|
40
40
|
|
41
41
|
Rake::Task["db:schema:dump"].reenable
|
42
42
|
Rake::Task["db:schema:dump"].invoke
|
43
|
-
end#end down task
|
44
|
-
|
43
|
+
end #end down task
|
44
|
+
|
45
|
+
task :up_without_running => :environment do
|
46
|
+
versions = RussellEdge::DataMigrator.new.run_up_without_migration
|
47
|
+
puts "================Up Without Running Data Migrations=========="
|
48
|
+
puts versions
|
49
|
+
puts "================================================="
|
50
|
+
end #up without running
|
51
|
+
end #end namespace
|
45
52
|
end
|
46
53
|
|
47
54
|
namespace :railties do
|
48
55
|
namespace :install do
|
49
56
|
# desc "Copies missing data_migrations from Railties (e.g. plugins, engines). You can specify Railties to use with FROM=railtie1,railtie2"
|
50
57
|
task :data_migrations => :environment do
|
51
|
-
to_load = ENV[
|
58
|
+
to_load = ENV["FROM"].blank? ? :all : ENV["FROM"].split(",").map { |n| n.strip }
|
52
59
|
#added to allow developer to perserve timestamps
|
53
|
-
preserve_timestamp = ENV[
|
60
|
+
preserve_timestamp = ENV["PRESERVE_TIMESTAMPS"].blank? ? false : (ENV["PRESERVE_TIMESTAMPS"].to_s.downcase == "true")
|
54
61
|
#refresh will replace migrations from engines
|
55
|
-
refresh = ENV[
|
62
|
+
refresh = ENV["REFRESH"].blank? ? false : (ENV["REFRESH"].to_s.downcase == "true")
|
56
63
|
railties = ActiveSupport::OrderedHash.new
|
57
64
|
Rails.application.railties.each do |railtie|
|
58
65
|
next unless to_load == :all || to_load.include?(railtie.railtie_name)
|
59
66
|
|
60
|
-
if railtie.respond_to?(:paths) && (path = railtie.paths[
|
67
|
+
if railtie.respond_to?(:paths) && (path = railtie.paths["db/data_migrations"].first)
|
61
68
|
railties[railtie.railtie_name] = path
|
62
69
|
end
|
63
70
|
end
|
@@ -76,6 +83,5 @@ namespace :railties do
|
|
76
83
|
:preserve_timestamp => preserve_timestamp,
|
77
84
|
:refresh => refresh)
|
78
85
|
end #data_migrations
|
79
|
-
|
80
86
|
end #install
|
81
87
|
end #railties
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_migrator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Holmes, Adam Hull
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
version: '0'
|
64
64
|
requirements: []
|
65
65
|
rubyforge_project:
|
66
|
-
rubygems_version: 2.
|
66
|
+
rubygems_version: 2.4.5.1
|
67
67
|
signing_key:
|
68
68
|
specification_version: 4
|
69
69
|
summary: Creates Data Migrations for data similar to schema migrations.
|