data_migrator 1.6 → 1.7

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE CHANGED
File without changes
data/README.rdoc CHANGED
File without changes
data/lib/data_migrator.rb CHANGED
@@ -10,11 +10,55 @@ module RussellEdge
10
10
  class DataMigrator
11
11
  REMOVE_FILES_REGEX = /^\./
12
12
 
13
- #class methods
14
- def self.next_migration_number
15
- Time.now.utc.strftime("%Y%m%d%H%M%S")
13
+ class << self
14
+ def next_migration_number
15
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
16
+ end
17
+
18
+ def initialize_data_migrations_table
19
+ puts "** data_migrations table missing creating now...."
20
+ puts ActiveRecord::Migrator.run(:up, File.join(File.dirname(__FILE__),'../db/migrate/'), 20100819181805)
21
+ puts "** done"
22
+ end
23
+
24
+ def prepare_migrations
25
+ target = "#{Rails.root}/db/data_migrations/"
26
+
27
+ # first copy all app data_migrations away
28
+ files = Dir["#{target}*.rb"]
29
+
30
+ unless files.empty?
31
+ FileUtils.mkdir_p "#{target}/ignore/app/"
32
+ FileUtils.cp files, "#{target}/ignore/app/"
33
+ puts "copied #{files.size} data_migrations to db/data_migrations/ignore/app"
34
+ end
35
+
36
+ dirs = Rails::Application::Railties.engines.map{|p| p.config.root.to_s}
37
+ files = Dir["{#{dirs.join(',')}}/db/data_migrations/*.rb"]
38
+
39
+ unless files.empty?
40
+ FileUtils.mkdir_p target
41
+ FileUtils.cp files, target
42
+ puts "copied #{files.size} migrations to db/data_migrations"
43
+ end
44
+ end
45
+
46
+ def cleanup_migrations
47
+ target = "#{Rails.root}/db/data_migrations/"
48
+
49
+ files = Dir["#{target}*.rb"]
50
+ unless files.empty?
51
+ FileUtils.rm files
52
+ puts "removed #{files.size} data_migrations from db/data_migrations"
53
+ end
54
+ files = Dir["#{target}/ignore/app/*.rb"]
55
+ unless files.empty?
56
+ FileUtils.cp files, target
57
+ puts "copied #{files.size} data_migrations back to db/data_migrations"
58
+ end
59
+ FileUtils.rm_rf "#{target}/ignore/app"
60
+ end
16
61
  end
17
- #end
18
62
 
19
63
  def initialize(migrations_path=nil)
20
64
  @default_migrations_path = migrations_path || "#{Rails.root}/db/data_migrations"
@@ -95,49 +139,11 @@ module RussellEdge
95
139
  puts "** Version #{passed_version} not found" unless found
96
140
 
97
141
  end
98
-
99
- def prepare_migrations
100
- target = "#{Rails.root}/db/data_migrations/"
101
-
102
- # first copy all app data_migrations away
103
- files = Dir["#{target}*.rb"]
104
-
105
- unless files.empty?
106
- FileUtils.mkdir_p "#{target}/ignore/app/"
107
- FileUtils.cp files, "#{target}/ignore/app/"
108
- puts "copied #{files.size} data_migrations to db/data_migrations/ignore/app"
109
- end
110
-
111
- dirs = Rails::Application::Railties.engines.map{|p| p.config.root.to_s}
112
- files = Dir["{#{dirs.join(',')}}/db/data_migrations/*.rb"]
113
-
114
- unless files.empty?
115
- FileUtils.mkdir_p target
116
- FileUtils.cp files, target
117
- puts "copied #{files.size} migrations to db/data_migrations"
118
- end
119
- end
120
-
121
- def cleanup_migrations
122
- target = "#{Rails.root}/db/data_migrations/"
123
-
124
- files = Dir["#{target}*.rb"]
125
- unless files.empty?
126
- FileUtils.rm files
127
- puts "removed #{files.size} data_migrations from db/data_migrations"
128
- end
129
- files = Dir["#{target}/ignore/app/*.rb"]
130
- unless files.empty?
131
- FileUtils.cp files, target
132
- puts "copied #{files.size} data_migrations back to db/data_migrations"
133
- end
134
- FileUtils.rm_rf "#{target}/ignore/app"
135
- end
136
142
 
137
143
  private
138
144
 
139
145
  def setup
140
- create_data_migrations_table unless data_migrations_table_exists?
146
+ RussellEdge::DataMigrator.initialize_data_migrations_table unless data_migrations_table_exists?
141
147
 
142
148
  unless File.directory? @default_migrations_path
143
149
  FileUtils.mkdir_p( @default_migrations_path)
@@ -196,7 +202,7 @@ module RussellEdge
196
202
  end
197
203
  end
198
204
  rescue Exception=>ex
199
- cleanup_migrations
205
+ RussellEdge::DataMigrator.cleanup_migrations
200
206
  raise ex
201
207
  end
202
208
  time_str = "(%.4fs)" % time.real
@@ -229,12 +235,6 @@ module RussellEdge
229
235
  table_names.include?('data_migrations')
230
236
  end
231
237
 
232
- def create_data_migrations_table
233
- puts "** data_migrations table missing creating now...."
234
- puts ActiveRecord::Migrator.run(:up, File.join(File.dirname(__FILE__),'../db/migrate/'), 20100819181805)
235
- puts "** done"
236
- end
237
-
238
238
  def seperate_file_parts(file)
239
239
  paths = file.split('/')
240
240
  filename = paths[paths.length - 1]
File without changes
@@ -2,39 +2,34 @@ namespace :db do
2
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
- data_migrator = RussellEdge::DataMigrator.new
6
- data_migrator.prepare_migrations
7
- data_migrator.migrate(nil, passed_version)
8
- data_migrator.cleanup_migrations
5
+ RussellEdge::DataMigrator.prepare_migrations
6
+ RussellEdge::DataMigrator.new.migrate(nil, passed_version)
7
+ RussellEdge::DataMigrator.cleanup_migrations
9
8
 
10
9
  end#end migrate_data task
11
10
 
12
11
  namespace :migrate_data do
13
12
  task :list_pending => :environment do
14
- data_migrator = RussellEdge::DataMigrator.new
15
- data_migrator.prepare_migrations
16
- pending_migrations = data_migrator.pending_migrations
13
+ RussellEdge::DataMigrator.prepare_migrations
14
+ pending_migrations = RussellEdge::DataMigrator.new.pending_migrations
17
15
  puts "================Pending Data Migrations=========="
18
16
  puts pending_migrations
19
17
  puts "================================================="
20
- data_migrator.cleanup_migrations
18
+ RussellEdge::DataMigrator.cleanup_migrations
21
19
  end#end list_pending task
22
20
 
23
21
  task :version => :environment do
24
- data_migrator = RussellEdge::DataMigrator.new
25
- version = data_migrator.get_current_version
26
-
22
+ version = RussellEdge::DataMigrator.new.get_current_version
27
23
  puts (version.nil?) ? "** No migrations ran" : "** Current version #{version}"
28
24
  end#end version task
29
25
 
30
26
  task :up => :environment do
31
27
  passed_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
32
28
  raise "VERSION is required" unless passed_version
33
-
34
- data_migrator = RussellEdge::DataMigrator.new
35
- data_migrator.prepare_migrations
36
- data_migrator.run_up(passed_version)
37
- data_migrator.cleanup_migrations
29
+
30
+ RussellEdge::DataMigrator.prepare_migrations
31
+ RussellEdge::DataMigrator.new.run_up(passed_version)
32
+ RussellEdge::DataMigrator.cleanup_migrations
38
33
 
39
34
  end#end up task
40
35
 
@@ -42,10 +37,9 @@ namespace :db do
42
37
  passed_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
43
38
  raise "VERSION is required" unless passed_version
44
39
 
45
- data_migrator = RussellEdge::DataMigrator.new
46
- data_migrator.prepare_migrations
47
- data_migrator.run_down(passed_version)
48
- data_migrator.cleanup_migrations
40
+ RussellEdge::DataMigrator.prepare_migrations
41
+ RussellEdge::DataMigrator.new.run_down(passed_version)
42
+ RussellEdge::DataMigrator.cleanup_migrations
49
43
 
50
44
  end#end down task
51
45
  end#end namespace
File without changes
data/test/test_helper.rb CHANGED
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_migrator
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.6'
4
+ version: '1.7'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-22 00:00:00.000000000Z
12
+ date: 2011-09-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2161558960 !ruby/object:Gem::Requirement
16
+ requirement: &2157691620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.3.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2161558960
24
+ version_requirements: *2157691620
25
25
  description: Allows you to create data migrations that can be run up and down to insert
26
26
  data into the database.
27
27
  email: russellfholmes@gmail.com