data_migrate 5.2.0 → 5.3.0

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
  SHA256:
3
- metadata.gz: aae65effdc868c62166684eabdeb9ab2799aa4804b6172fe4ff541b1193fba54
4
- data.tar.gz: 3c50deaf50da13456a9e078ae0df07d269335b312863c88b0807f58bb3fdcffa
3
+ metadata.gz: 9462f36e74230a90ba6e6d8eecc2372bd2b95645728e2791ff58fe46a0603a67
4
+ data.tar.gz: b8f720b2a4f81de75c4ab7a45bcb6f95a472e17569e6d06297cdc9b3bbf1407d
5
5
  SHA512:
6
- metadata.gz: 650d0315aa2cbb3549fdd1104bf2f471a141519aee4b51589a988b027e496a4ea8659b160e651a5f8b9a88cd7fe6a41822e0de65b96e3e01591bdef4cac3e3c7
7
- data.tar.gz: 21f4a447c422b8470a4968a48b6e9e56fdcf798bff9f92ef2dcf1a84283d6c790f73dd1d54c0992e15cec11ca4ac10b0ec429a7fe68d5f28fb70e2a7d4119d17
6
+ metadata.gz: 481d64df974f86ad1c81f8ab064afd16ccd9596b924de2ea09f8060bc85f4cf39cf4501af54e45d473d00c71ab8a272173e4a898a421d2cef0f8993b64bdfe5f
7
+ data.tar.gz: 27e18b67499e98a64cced4c95ad5c145f9d0b4213be841966c8c38f90dbd2d9e2fcac55b70afa02ceb2917c54851cae40e8e34df32782fffb4ca3e93b2da989d
data/README.md CHANGED
@@ -4,6 +4,7 @@ Data Migrate
4
4
  - [![Version](http://img.shields.io/gem/v/data_migrate.svg?style=flat-square)](https://rubygems.org/gems/data_migrate)
5
5
  - [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
6
6
  - [![Travis](https://img.shields.io/travis/ilyakatz/data-migrate.svg)](https://travis-ci.org/ilyakatz/data-migrate)
7
+ - [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
7
8
 
8
9
 
9
10
  Run data migrations alongside schema migrations.
@@ -144,6 +145,17 @@ With 'up' and 'down', you can specify the option 'BOTH', which defaults to false
144
145
 
145
146
  `data_migrate` respects `ActiveRecord::Base.dump_schema_after_migration`. If it is set to `false`, data schema file will not be generated
146
147
 
148
+
149
+ By default, data migrations are added to the `db/data/` path.
150
+ You can override this setting in `config/initializers/data_migrate.rb`
151
+
152
+ ```ruby
153
+ DataMigrate.configure do |config|
154
+ config.data_migrations_path = "db/awesomepath/"
155
+ end
156
+
157
+ ```
158
+
147
159
  ## Capistrano Support
148
160
 
149
161
  The gem comes with a capistrano task that can be used instead of `capistrano/rails/migrations`.
@@ -29,12 +29,7 @@ end
29
29
  require File.join(File.dirname(__FILE__), "data_migrate", "railtie")
30
30
  require File.join(File.dirname(__FILE__), "data_migrate", "tasks/data_migrate_tasks")
31
31
  require File.join(File.dirname(__FILE__), "data_migrate", "legacy_migrator")
32
+ require File.join(File.dirname(__FILE__), "data_migrate", "config")
32
33
 
33
34
  module DataMigrate
34
- include ActiveSupport::Configurable
35
- class << self
36
- def configure
37
- yield config
38
- end
39
- end
40
35
  end
@@ -0,0 +1,21 @@
1
+ module DataMigrate
2
+ include ActiveSupport::Configurable
3
+ class << self
4
+
5
+ def configure
6
+ yield config
7
+ end
8
+
9
+ def config
10
+ @config ||= Config.new
11
+ end
12
+ end
13
+
14
+ class Config
15
+ attr_accessor :data_migrations_path
16
+
17
+ def initialize
18
+ @data_migrations_path = "db/data/"
19
+ end
20
+ end
21
+ end
@@ -38,7 +38,7 @@ module DataMigrate
38
38
  end
39
39
 
40
40
  def migrations_path
41
- "db/data"
41
+ DataMigrate.config.data_migrations_path
42
42
  end
43
43
 
44
44
  ##
@@ -63,7 +63,7 @@ module DataMigrate
63
63
  # @param (String) filename
64
64
  # @return (MatchData)
65
65
  def match(filename)
66
- /(\d{14})_(.+)\.rb/.match(filename)
66
+ /(\d{14})_(.+)\.rb$/.match(filename)
67
67
  end
68
68
 
69
69
  private
@@ -52,7 +52,7 @@ module DataMigrate
52
52
 
53
53
  def migration_files(db_list)
54
54
  file_list = []
55
- Dir.foreach(File.join(root_folder, "db", "data")) do |file|
55
+ Dir.foreach(File.join(root_folder, DataMigrate.config.data_migrations_path)) do |file|
56
56
  # only files matching "20091231235959_some_name.rb" pattern
57
57
  if match_data = DataMigrate::DataMigrator.match(file)
58
58
  status = db_list.delete(match_data[1]) ? "up" : "down"
@@ -3,11 +3,7 @@ module DataMigrate
3
3
  module DataMigrateTasks
4
4
  extend self
5
5
  def migrations_paths
6
- @migrations_paths ||= begin
7
- if Rails.application && Rails.application.paths["data/migrate"]
8
- Rails.application.paths["data/migrate"].to_a
9
- end
10
- end
6
+ @migrations_paths ||= DataMigrate.config.data_migrations_path
11
7
  end
12
8
 
13
9
  def migrate
@@ -16,8 +12,7 @@ module DataMigrate
16
12
  if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2
17
13
  DataMigrate::MigrationContext.new(migrations_paths).migrate(target_version)
18
14
  else
19
- paths = migrations_paths || "db/data/"
20
- DataMigrate::DataMigrator.migrate(paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
15
+ DataMigrate::DataMigrator.migrate(migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
21
16
  end
22
17
  end
23
18
  end
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "5.2.0".freeze
2
+ VERSION = "5.3.0".freeze
3
3
  end
@@ -2,6 +2,7 @@ require "generators/data_migrate"
2
2
  require "rails/generators"
3
3
  require "rails/generators/active_record/migration"
4
4
  require "rails/generators/migration"
5
+ require "data_migrate/config"
5
6
 
6
7
  module DataMigrate
7
8
  module Generators
@@ -13,7 +14,7 @@ module DataMigrate
13
14
 
14
15
  def create_data_migration
15
16
  set_local_assigns!
16
- migration_template "data_migration.rb", "db/data/#{file_name}.rb"
17
+ migration_template "data_migration.rb", "#{data_migrations_path}#{file_name}.rb"
17
18
  end
18
19
 
19
20
  protected
@@ -34,6 +35,10 @@ module DataMigrate
34
35
  "ActiveRecord::Migration"
35
36
  end
36
37
  end
38
+
39
+ def data_migrations_path
40
+ DataMigrate.config.data_migrations_path
41
+ end
37
42
  end
38
43
  end
39
44
  end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe DataMigrate::Config do
4
+
5
+ it "sets default data_migrations_path path" do
6
+ expect(DataMigrate.config.data_migrations_path).to eq "db/data/"
7
+ end
8
+
9
+ describe "data migration path configured" do
10
+ before do
11
+ DataMigrate.configure do |config|
12
+ config.data_migrations_path = "db/awesome/"
13
+ end
14
+ end
15
+
16
+ after do
17
+ DataMigrate.configure do |config|
18
+ config.data_migrations_path = "db/data/"
19
+ end
20
+ end
21
+
22
+ it do
23
+ expect(DataMigrate.config.data_migrations_path).to eq "db/awesome/"
24
+ end
25
+ end
26
+ end
@@ -62,6 +62,15 @@ describe DataMigrate::StatusService do
62
62
  expect(stream.read).to include expected
63
63
  end
64
64
 
65
+ it "excludes files without .rb extension" do
66
+ stream = StringIO.new
67
+ service.dump(ActiveRecord::Base.connection, stream)
68
+ stream.rewind
69
+
70
+ expected = "20181128000207 Excluded file"
71
+ expect(stream.read).to_not include expected
72
+ end
73
+
65
74
  it "shows missing file migration" do
66
75
  stream = StringIO.new
67
76
  service.dump(ActiveRecord::Base.connection, stream)
@@ -0,0 +1 @@
1
+ # This file should be excluded
@@ -48,7 +48,7 @@ namespace :db do
48
48
  migrations.each do |migration|
49
49
  if migration[:kind] == :data
50
50
  ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
51
- DataMigrate::DataMigrator.run(migration[:direction], "db/data/", migration[:version])
51
+ DataMigrate::DataMigrator.run(migration[:direction], data_migrations_path, migration[:version])
52
52
  else
53
53
  ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
54
54
  DataMigrate::SchemaMigration.run(
@@ -93,7 +93,7 @@ namespace :db do
93
93
  migrations.each do |migration|
94
94
  if migration[:kind] == :data
95
95
  ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
96
- DataMigrate::DataMigrator.run(:up, "db/data/", migration[:version])
96
+ DataMigrate::DataMigrator.run(:up, data_migrations_path, migration[:version])
97
97
  else
98
98
  ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
99
99
  DataMigrate::SchemaMigration.run(:up, "db/migrate/", migration[:version])
@@ -121,7 +121,7 @@ namespace :db do
121
121
  migrations.each do |migration|
122
122
  if migration[:kind] == :data
123
123
  ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
124
- DataMigrate::DataMigrator.run(:down, "db/data/", migration[:version])
124
+ DataMigrate::DataMigrator.run(:down, data_migrations_path, migration[:version])
125
125
  else
126
126
  ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
127
127
  DataMigrate::SchemaMigration.run(:down, "db/migrate/", migration[:version])
@@ -147,7 +147,7 @@ namespace :db do
147
147
  )
148
148
  file_list = []
149
149
 
150
- Dir.foreach(File.join(Rails.root, 'db', 'data')) do |file|
150
+ Dir.foreach(File.join(Rails.root, data_migrations_path)) do |file|
151
151
  # only files matching "20091231235959_some_name.rb" pattern
152
152
  if match_data = /(\d{14})_(.+)\.rb/.match(file)
153
153
  status = db_list_data.delete(match_data[1]) ? 'up' : 'down'
@@ -191,7 +191,7 @@ namespace :db do
191
191
  past_migrations[0..(step - 1)].each do | past_migration |
192
192
  if past_migration[:kind] == :data
193
193
  ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
194
- DataMigrate::DataMigrator.run(:down, "db/data/", past_migration[:version])
194
+ DataMigrate::DataMigrator.run(:down, data_migrations_path, past_migration[:version])
195
195
  elsif past_migration[:kind] == :schema
196
196
  ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
197
197
  ActiveRecord::Migrator.run(:down, "db/migrate/", past_migration[:version])
@@ -277,7 +277,7 @@ namespace :data do
277
277
  assure_data_schema_table
278
278
  version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
279
279
  raise "VERSION is required" unless version
280
- DataMigrate::DataMigrator.run(:up, "db/data/", version)
280
+ DataMigrate::DataMigrator.run(:up, data_migrations_path, version)
281
281
  Rake::Task["data:dump"].invoke
282
282
  end
283
283
 
@@ -286,7 +286,7 @@ namespace :data do
286
286
  version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
287
287
  raise "VERSION is required" unless version
288
288
  assure_data_schema_table
289
- DataMigrate::DataMigrator.run(:down, "db/data/", version)
289
+ DataMigrate::DataMigrator.run(:down, data_migrations_path, version)
290
290
  Rake::Task["data:dump"].invoke
291
291
  end
292
292
 
@@ -304,7 +304,7 @@ namespace :data do
304
304
  task :rollback => :environment do
305
305
  assure_data_schema_table
306
306
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
307
- DataMigrate::DataMigrator.rollback('db/data/', step)
307
+ DataMigrate::DataMigrator.rollback(data_migrations_path, step)
308
308
  Rake::Task["data:dump"].invoke
309
309
  end
310
310
 
@@ -316,7 +316,7 @@ namespace :data do
316
316
  # DataMigrate::DataMigrator.forward('db/data/', step)
317
317
  migrations = pending_data_migrations.reverse.pop(step).reverse
318
318
  migrations.each do | pending_migration |
319
- DataMigrate::DataMigrator.run(:up, "db/data/", pending_migration[:version])
319
+ DataMigrate::DataMigrator.run(:up, data_migrations_path, pending_migration[:version])
320
320
  end
321
321
  Rake::Task["data:dump"].invoke
322
322
  end
@@ -389,3 +389,7 @@ end
389
389
  def assure_data_schema_table
390
390
  DataMigrate::DataMigrator.assure_data_schema_table
391
391
  end
392
+
393
+ def data_migrations_path
394
+ DataMigrate.config.data_migrations_path
395
+ 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: 5.2.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew J Vargo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-10-03 00:00:00.000000000 Z
13
+ date: 2018-12-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -200,6 +200,7 @@ files:
200
200
  - lib/capistrano/data_migrate.rb
201
201
  - lib/capistrano/data_migrate/migrate.rb
202
202
  - lib/data_migrate.rb
203
+ - lib/data_migrate/config.rb
203
204
  - lib/data_migrate/data_migrator.rb
204
205
  - lib/data_migrate/data_migrator_five.rb
205
206
  - lib/data_migrate/data_schema.rb
@@ -222,6 +223,7 @@ files:
222
223
  - lib/generators/data_migration/templates/data_migration.rb
223
224
  - lib/generators/data_migration/templates/migration.rb
224
225
  - screenshot.png
226
+ - spec/data_migrate/config_spec.rb
225
227
  - spec/data_migrate/data_migrator_spec.rb
226
228
  - spec/data_migrate/data_schema_migration_spec.rb
227
229
  - spec/data_migrate/data_spec.rb
@@ -239,6 +241,7 @@ files:
239
241
  - spec/db/5.0/20171231235959_super_update.rb
240
242
  - spec/db/data/20091231235959_some_name.rb
241
243
  - spec/db/data/20171231235959_super_update.rb
244
+ - spec/db/data/20181128000207_excluded_file.rb.other_ext
242
245
  - spec/db/migrate/4.2/20131111111111_late_migration.rb
243
246
  - spec/db/migrate/4.2/20202020202011_db_migration.rb
244
247
  - spec/db/migrate/5.0/20131111111111_late_migration.rb
@@ -280,6 +283,7 @@ signing_key:
280
283
  specification_version: 4
281
284
  summary: Rake tasks to migrate data alongside schema changes.
282
285
  test_files:
286
+ - spec/data_migrate/config_spec.rb
283
287
  - spec/data_migrate/data_migrator_spec.rb
284
288
  - spec/data_migrate/data_schema_migration_spec.rb
285
289
  - spec/data_migrate/data_spec.rb
@@ -297,6 +301,7 @@ test_files:
297
301
  - spec/db/5.0/20171231235959_super_update.rb
298
302
  - spec/db/data/20091231235959_some_name.rb
299
303
  - spec/db/data/20171231235959_super_update.rb
304
+ - spec/db/data/20181128000207_excluded_file.rb.other_ext
300
305
  - spec/db/migrate/4.2/20131111111111_late_migration.rb
301
306
  - spec/db/migrate/4.2/20202020202011_db_migration.rb
302
307
  - spec/db/migrate/5.0/20131111111111_late_migration.rb