seed_migration 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e633de5d286622fde82f7ce04b6cc0c13e7637a
4
- data.tar.gz: 373a4dc6630258bb1ae761e54705bece7f963e9d
3
+ metadata.gz: 38f8055cf600a0ea55f7ae4b315f1b534a448779
4
+ data.tar.gz: 2629240a52ecda680e6fec7b29ad46f05a0eba20
5
5
  SHA512:
6
- metadata.gz: 36591834e7513fedecb675524531a9d853ee10efefb2739f1c7733d58a6f82b17e1b1461c9300c4f92e4438b6055cf89fc0be4b8417ea55a2b30165adb1e248f
7
- data.tar.gz: 806ca774600313498545b9ea06a0864a8e2f6e13ea05b85fa140380cd185b9d11f052d19fcbbb0333dfc723d08347467cc238bb6ecb1cd5fe6fcd4bea4d32bcf
6
+ metadata.gz: 78cf3c5d47ec09b44d44404d4ef7c26881d4365318517984fc34698285cf336de5c40cb2e7290a17cf37a5d1e3e95537128e992020aac66f60ad2ab3f3d33fec
7
+ data.tar.gz: b1e061859b4e9fa78a4b43d4d6fc7cdb37c6d337b589f2d4cd8c57b0c4d83557bc65d1ab3664b7a8ca04c5d6dbe6aaf5efdf8c9dedaec5eaa902f46bc9829b48
@@ -68,6 +68,16 @@ module SeedMigration
68
68
  migration = migration_path(migration)
69
69
  new(migration).up
70
70
  end
71
+ end
72
+
73
+ def self.run_migrations(filename = nil)
74
+ if filename.blank?
75
+ # Run any outstanding migrations
76
+ run_new_migrations
77
+ else
78
+ path = self.migration_path(filename)
79
+ new(path).up
80
+ end
71
81
  create_seed_file
72
82
  end
73
83
 
@@ -75,10 +85,15 @@ module SeedMigration
75
85
  return SeedMigration::DataMigration.maximum("version")
76
86
  end
77
87
 
78
- def self.rollback_migrations(steps = 1)
79
- to_run = get_last_x_migrations(steps)
80
- to_run.each do |migration|
81
- new(migration).down
88
+ def self.rollback_migrations(filename = nil, steps = 1)
89
+ if filename.blank?
90
+ to_run = get_last_x_migrations(steps)
91
+ to_run.each do |migration|
92
+ new(migration).down
93
+ end
94
+ else
95
+ path = migration_path(filename)
96
+ new(path).down
82
97
  end
83
98
  create_seed_file
84
99
  end
@@ -86,7 +101,7 @@ module SeedMigration
86
101
  def self.bootstrap(last_timestamp = nil)
87
102
  # replace with logger ?
88
103
  p "Assume migrated up to #{last_timestamp}"
89
- files = SeedMigration::Migrator.get_migration_files(last_timestamp.to_s)
104
+ files = get_migration_files(last_timestamp.to_s)
90
105
  files.each do |file|
91
106
  name = file.split('/').last
92
107
  version = name.split('_').first
@@ -163,7 +178,7 @@ module SeedMigration
163
178
  end
164
179
 
165
180
  def self.get_migration_files(last_timestamp = nil)
166
- files = Dir.glob(SeedMigration::Migrator.migration_path("*_*.rb"))
181
+ files = Dir.glob(migration_path("*_*.rb"))
167
182
  if last_timestamp.present?
168
183
  files.delete_if do |file|
169
184
  timestamp = File.basename(file).split('_').first
@@ -223,9 +238,17 @@ SeedMigration::Migrator.bootstrap(#{last_migration})
223
238
  attributes.sort.each do |key, value|
224
239
  sorted_attributes[key] = value
225
240
  end
241
+
242
+ if Rails::VERSION::MAJOR == 3
243
+ model_creation_string = "#{instance.class}.create(#{JSON.parse(sorted_attributes.to_json).to_s}, :without_protection => true)"
244
+ elsif Rails::VERSION::MAJOR == 4
245
+ model_creation_string = "#{instance.class}.create(#{JSON.parse(sorted_attributes.to_json).to_s})"
246
+ end
247
+
248
+ # With pretty indents, please.
226
249
  return <<-eos
227
250
 
228
- #{instance.class}.create(#{JSON.parse(sorted_attributes.to_json).to_s}, :without_protection => true)
251
+ #{model_creation_string}
229
252
  eos
230
253
  end
231
254
  end
@@ -1,3 +1,3 @@
1
1
  module SeedMigration
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,25 +1,11 @@
1
1
  namespace :seed do
2
2
  desc "Run new data migrations."
3
3
  task :migrate => :environment do
4
- filename = ENV["MIGRATION"]
5
- if filename.blank?
6
- # Run any outstanding migrations
7
- SeedMigration::Migrator.run_new_migrations
8
- else
9
- path = SeedMigration::Migrator.migration_path(filename)
10
- SeedMigration::Migrator.new(path).up
11
- end
4
+ SeedMigration::Migrator.run_migrations(ENV['MIGRATION'])
12
5
  end
13
6
 
14
7
  desc "Revert last data migration."
15
8
  task :rollback => :environment do
16
- filename = ENV["MIGRATION"]
17
- if filename.blank?
18
- steps = ENV["STEP"] || 1
19
- SeedMigration::Migrator.rollback_migrations(steps)
20
- else
21
- path = SeedMigration::Migrator.migration_path(filename)
22
- SeedMigration::Migrator.new(path).down
23
- end
9
+ SeedMigration::Migrator.rollback_migrations(ENV["MIGRATION"], ENV["STEP"] || 1)
24
10
  end
25
11
  end
metadata CHANGED
@@ -1,15 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seed_migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy O'Neill
8
8
  - Daniel Schwartz
9
+ - Ilya Rubnich
10
+ - Pierre Jambet
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
- date: 2014-06-10 00:00:00.000000000 Z
14
+ date: 2014-06-17 00:00:00.000000000 Z
13
15
  dependencies:
14
16
  - !ruby/object:Gem::Dependency
15
17
  name: sqlite3
@@ -85,6 +87,8 @@ description: Rails gem for Data Migrations
85
87
  email:
86
88
  - aoneill@harrys.com
87
89
  - daniel@harrys.com
90
+ - ilya@harrys.com
91
+ - pierre@harrys.com
88
92
  executables: []
89
93
  extensions: []
90
94
  extra_rdoc_files: []