data_migrate 5.3.2 → 6.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rbenv-gemsets +2 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +7 -4
  5. data/Appraisals +7 -9
  6. data/Changelog.md +36 -4
  7. data/Gemfile +2 -0
  8. data/Gemfile.rails5.1 +1 -1
  9. data/README.md +20 -20
  10. data/data_migrate.gemspec +2 -2
  11. data/gemfiles/rails_4.2.gemfile +2 -1
  12. data/gemfiles/rails_5.0.gemfile +1 -1
  13. data/gemfiles/rails_5.1.gemfile +1 -1
  14. data/gemfiles/rails_5.2.gemfile +1 -1
  15. data/gemfiles/rails_6.0.gemfile +8 -0
  16. data/lib/data_migrate.rb +13 -4
  17. data/lib/data_migrate/data_migrator.rb +6 -0
  18. data/lib/data_migrate/data_migrator_five.rb +9 -3
  19. data/lib/data_migrate/schema_migration_five.rb +1 -1
  20. data/lib/data_migrate/schema_migration_six.rb +31 -0
  21. data/lib/data_migrate/tasks/data_migrate_tasks.rb +2 -1
  22. data/lib/data_migrate/version.rb +1 -1
  23. data/lib/generators/data_migration/data_migration_generator.rb +5 -1
  24. data/spec/data_migrate/config_spec.rb +3 -2
  25. data/spec/data_migrate/data_migrator_spec.rb +21 -0
  26. data/spec/data_migrate/database_tasks_spec.rb +4 -10
  27. data/spec/data_migrate/migration_context_spec.rb +13 -4
  28. data/spec/data_migrate/schema_migration_spec.rb +3 -1
  29. data/spec/data_migrate/status_service_spec.rb +1 -1
  30. data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +2 -17
  31. data/spec/db/{4.2 → 6.0}/20091231235959_some_name.rb +1 -1
  32. data/spec/db/{4.2 → 6.0}/20171231235959_super_update.rb +1 -1
  33. data/spec/db/data-6.0/20091231235959_some_name.rb +9 -0
  34. data/spec/db/data-6.0/20171231235959_super_update.rb +9 -0
  35. data/spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext +1 -0
  36. data/spec/db/migrate/6.0/20131111111111_late_migration.rb +9 -0
  37. data/spec/db/migrate/6.0/20202020202011_db_migration.rb +9 -0
  38. data/spec/generators/data_migration/data_migration_generator_spec.rb +33 -0
  39. data/spec/spec_helper.rb +26 -4
  40. data/tasks/databases.rake +1 -1
  41. metadata +27 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 737ac14150dfe99227e19eff42fbe27ad4ed670abf64352497de7d795bb63ffe
4
- data.tar.gz: 44d29c907e88b2fa0cfb2686b9d5a61ac52be77b2d80d528840f3fa7be150a95
3
+ metadata.gz: 3f4da014e11358e7723df55f6406cbf37ce2e493ecc88c9c0491a22ec336958c
4
+ data.tar.gz: d3f2c34344cf70447c900085a725803128bbb38ca7ef2cce66c7fd309b990056
5
5
  SHA512:
6
- metadata.gz: 01436d19ffc4671f27bdbdade83539d8c4a2e2b9ff3a632740beb8851cdeea43c1d39edc6288be41d6d695f268c70706f09a016412438a92c44cc1e86495f2bd
7
- data.tar.gz: d51939c5695ff458db14bb5df3f9a276e3a8d576fcb3372573fa4babbd2bdef29df63e2e51942c52b663f3c76fdeffb3d92769ae042cf0ecf50777cceade98bd
6
+ metadata.gz: b6cbbc544a5454293c4867e3b576c432138cad92bafb21c72b0ce34ac3adfd78fcbbe70bf6317518625463e0e661096b0f28d2912ddc00268fe159b54c638bd2
7
+ data.tar.gz: d4695470310defaf03f7a69525c279b4d7c78da59d7046f04b5f7708c8843a0be14dfc8682312cb9c47e8b2f6d75878d03042bdfd2fcb7e167ac35e125dafb89
data/.rbenv-gemsets ADDED
@@ -0,0 +1,2 @@
1
+ data-migrate
2
+ -global
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.1
data/.travis.yml CHANGED
@@ -1,12 +1,15 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.9
4
- - 2.3.7
5
3
  - 2.4.4
6
- - 2.5.1
4
+ - 2.5.5
5
+ - 2.6.2
7
6
  script: bundle exec rspec
8
7
  gemfile:
9
- - gemfiles/rails_4.2.gemfile
10
8
  - gemfiles/rails_5.0.gemfile
11
9
  - gemfiles/rails_5.1.gemfile
12
10
  - gemfiles/rails_5.2.gemfile
11
+ - gemfiles/rails_6.0.gemfile
12
+ matrix:
13
+ exclude:
14
+ - rvm: 2.4.4
15
+ gemfile: gemfiles/rails_6.0.gemfile
data/Appraisals CHANGED
@@ -1,17 +1,15 @@
1
- appraise 'rails-4.2' do
2
- gem 'rails', '4.2.8'
3
- # Nokogiri 1.7+ requires Ruby 2.1+
4
- gem 'nokogiri', '1.6.8.1'
5
- end
6
-
7
1
  appraise 'rails-5.0' do
8
- gem 'rails', '5.0.3'
2
+ gem 'rails', '5.0.7.2'
9
3
  end
10
4
 
11
5
  appraise 'rails-5.1' do
12
- gem 'rails', '5.1'
6
+ gem 'rails', '5.1.7'
13
7
  end
14
8
 
15
9
  appraise 'rails-5.2' do
16
- gem 'rails', '~> 5.2.0'
10
+ gem 'rails', '~> 5.2.3'
11
+ end
12
+
13
+ appraise 'rails-6.0' do
14
+ gem 'rails', '~> 6.0.0.beta3'
17
15
  end
data/Changelog.md CHANGED
@@ -1,16 +1,44 @@
1
- Changelog
2
- =========
1
+ # Changelog
2
+
3
+ ## 6.0.5
4
+
5
+ Fixing `needs_migration?` method for Rails 5.2 and up [EnomaDebby](https://github.com/EnomaDebby)
6
+
7
+ ## 6.0.4.beta
8
+
9
+ Fix rolling back schema migrations failing for Rails 5.2 and above
10
+
11
+ ## 6.0.3.beta
12
+
13
+ Compatiblity with Rails 6 RC2 [y-yagi](https://github.com/y-yagi)
14
+
15
+ ## 6.0.1.beta
16
+
17
+ Fix migrations being generated in wrong folder
18
+
19
+ ## 6.0.0
20
+
21
+ Support for Rails 6
22
+ No longer supporting Rails 4.2
23
+
24
+ ## 5.3.3
25
+
26
+ Ruby 2.2 and 2.3 are no longer actively validated with tests since they are both EOL
3
27
 
4
28
  ## 5.3.2
29
+
5
30
  Fix capistrano migration tasks to only skip migrations if there are no changes in the db/data and db/migrate folders
6
31
 
7
32
  ## 5.3.1
33
+
8
34
  Change database task to use data_migrations_path_configuration
9
35
 
10
36
  ## 5.3.0
11
- Add support to configure data migration path
37
+
38
+ Add support to configure data migration path
12
39
 
13
40
  ## 5.1.0
41
+
14
42
  Fixes to `db:schema:load:with_data` + `db:structure:load:with_data` definition, thanks to [craineum](https://github.com/craineum)
15
43
 
16
44
  ## 5.0.0
@@ -37,11 +65,15 @@ Deprecated support for rails 4.0
37
65
  Improvements to timestamped migrations, thanks to [Pierre-Michard](https://github.com/Pierre-Michard)
38
66
 
39
67
  ## 3.4.0
68
+
40
69
  `rake data:migrate:status` to return result in chronological order
70
+
41
71
  ## 3.3.1
72
+
42
73
  Regression fix, thanks to [subakva](https://github.com/subakva)
43
74
 
44
75
  ## 3.3.0
76
+
45
77
  The concept of schema:dump to data migrations, thanks to
46
78
  [tobyndockerill](https://github.com/tobyndockerill)
47
79
 
@@ -50,8 +82,8 @@ The concept of schema:dump to data migrations, thanks to
50
82
  data_migrate table into rails schema dump, thanks to
51
83
  [jturkel](https://github.com/jturkel)
52
84
 
53
-
54
85
  ## 3.2.0
86
+
55
87
  - Add support for Rails 5.1
56
88
  - No longer testing EOL rubies
57
89
 
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in data_migrate.gemspec
4
+ gem 'rails', path: "~/ws/rails"
5
+ gem 'sqlite3', "~> 1.4"
4
6
  gemspec
data/Gemfile.rails5.1 CHANGED
@@ -2,4 +2,4 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in data_migrate.gemspec
4
4
  gemspec
5
- gem 'rails', '~> 5.1'
5
+ gem 'rails', '~> 5.1.7'
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
- Data Migrate
2
- ====
1
+ # Data Migrate
3
2
 
4
3
  - [![Version](http://img.shields.io/gem/v/data_migrate.svg?style=flat-square)](https://rubygems.org/gems/data_migrate)
5
4
  - [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
6
5
  - [![Travis](https://img.shields.io/travis/ilyakatz/data-migrate.svg)](https://travis-ci.org/ilyakatz/data-migrate)
7
6
  - [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
8
7
 
9
-
10
8
  Run data migrations alongside schema migrations.
11
9
 
12
10
  Data migrations are stored in `db/data`. They act like schema
@@ -19,13 +17,13 @@ is the place to do it.
19
17
  # Why should I use this?
20
18
 
21
19
  Its seems when a project hits a certain size, I get to manipulate data
22
- outside the application itself. Changing defaults, new validations,
20
+ outside the application itself. Changing defaults, new validations,
23
21
  one-to-one to one-to-many... I found it a pain and dodgy to have to
24
22
  step up migrations one by one, run a ruby script of some sort, then
25
- resume migrations. It tanks a lot of the automation of deploy.
23
+ resume migrations. It tanks a lot of the automation of deploy.
26
24
 
27
25
  If you don't use the one off scripts, you could do it as a regular
28
- migration. It'd be much better to keep concerns separate. The benefit
26
+ migration. It'd be much better to keep concerns separate. The benefit
29
27
  of having them separate has to do with your data model.
30
28
 
31
29
  For instance, lets take an absurd example, to illustrate: You have
@@ -34,28 +32,29 @@ After some use, you decide you are going to be a trend setter,
34
32
  and want only one comment per post, and just the text.
35
33
 
36
34
  Given that you:
35
+
37
36
  - write a migration to add a comment column to `Post`
38
37
  - write a migration to move the contents of the first comments to the `Post`
39
38
  - drop the `column_id` column from `Post`
40
39
  - drop the `Comment` model
41
40
  - fix all your tests
42
41
 
43
- You've just got bit. When you `rake setup:development`, the mess gets
42
+ You've just got bit. When you `rake setup:development`, the mess gets
44
43
  mad at you after it creates your database, and starts cranking through
45
- migrations. It gets to the part where you iterate over the comments
46
- and it blows up. You don't have a `Comment` model anymore for it to
47
- even try and get 'all' from. You think you are smarter, and wrap the
44
+ migrations. It gets to the part where you iterate over the comments
45
+ and it blows up. You don't have a `Comment` model anymore for it to
46
+ even try and get 'all' from. You think you are smarter, and wrap the
48
47
  ActiveRecord call in a conditional based on the environment.
49
48
 
50
49
  That's fine until you get that QA gal, and she wants her own thing.
51
50
  Then the UI people get tired of waiting for the full stack to load on page
52
51
  refreshes, so you have to edit past migrations...
53
52
 
54
- With Data Migrate, you have the control. You can generate your
53
+ With Data Migrate, you have the control. You can generate your
55
54
  migrations as schema or data as you would as your work flow. For
56
55
  setting tasks that don't require any intermediate AR activity, like
57
- dev and test, you stick with `db:migrate`. For production and QA, you
58
- change their scripts to `db:migrate:with_data`. Of course you want to
56
+ dev and test, you stick with `db:migrate`. For production and QA, you
57
+ change their scripts to `db:migrate:with_data`. Of course you want to
59
58
  test your migration, so you have the choice of `db:migrate:with_data` or
60
59
  `data:migrate` to just capture that data change.
61
60
 
@@ -70,7 +69,7 @@ table to track all the goodness.
70
69
 
71
70
  ## Rails Support
72
71
 
73
- Support Rails 4.2 through 5.2
72
+ Support Rails 5.0 through 6.0
74
73
 
75
74
  ### Important notes for older versions
76
75
 
@@ -93,6 +92,7 @@ If you've installed previous to v1.1.0, you'll want to delete the
93
92
  `create_data_migrations_table` migration.
94
93
 
95
94
  ## Installation
95
+
96
96
  Add the gem to your project
97
97
 
98
98
  # Gemfile
@@ -104,7 +104,6 @@ So you know, when you use one of the provide rake tasks, a table
104
104
  called `data_migrations` will be created in your database. This
105
105
  is to mirror the way the standard `db` rake tasks work.
106
106
 
107
-
108
107
  ## Usage
109
108
 
110
109
  ### Generating Migrations
@@ -138,15 +137,15 @@ You can generate a data migration as you would a schema migration:
138
137
 
139
138
  Tasks work as they would with the 'vanilla' db version. The 'with_data' addition to the 'db' tasks will run the task in the context of both the data and schema migrations. That is, rake db:rollback:with_data will check to see if it was a schema or data migration invoked last, and do that. Tasks invoked in that space also have an additional line of output, indicating if the action is performed on data or schema.
140
139
 
141
- With 'up' and 'down', you can specify the option 'BOTH', which defaults to false. Using true, will migrate both the data and schema (in the desired direction) if they both match the version provided. Again, going up, schema is given precedence. Down its data.
140
+ With 'up' and 'down', you can specify the option 'BOTH', which defaults to false. Using true, will migrate both the data and schema (in the desired direction) if they both match the version provided. Again, going up, schema is given precedence. Down its data.
142
141
 
143
142
  `rake db:migrate:status:with_data` provides and additional column to indicate which type of migration.
143
+
144
144
  ### Configuration
145
145
 
146
146
  `data_migrate` respects `ActiveRecord::Base.dump_schema_after_migration`. If it is set to `false`, data schema file will not be generated
147
147
 
148
-
149
- By default, data migrations are added to the `db/data/` path.
148
+ By default, data migrations are added to the `db/data/` path.
150
149
  You can override this setting in `config/initializers/data_migrate.rb`
151
150
 
152
151
  ```ruby
@@ -176,13 +175,14 @@ Run tests for a specific version of Rails
176
175
 
177
176
  ```
178
177
  bundle exec appraisal install
179
- bundle exec appraisal rails-4.2 rspec
180
178
  bundle exec appraisal rails-5.0 rspec
179
+ bundle exec appraisal rails-5.2 rspec
181
180
  ```
182
181
 
183
182
  ## Thanks
183
+
184
184
  [Andrew J Vargo](http://github.com/ajvargo) Andrew was the original creator and maintainer of this project!
185
185
 
186
186
  [Jeremy Durham](http://jeremydurham.com/) for fleshing out the idea with me, and providing guidance.
187
187
 
188
- You! Yes, you. Thanks for checking it out.
188
+ You! Yes, you. Thanks for checking it out.
data/data_migrate.gemspec CHANGED
@@ -15,14 +15,14 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.rubyforge_project = "data_migrate"
17
17
 
18
- s.add_dependency('rails', '>= 4.2')
18
+ s.add_dependency('rails', '>= 5.0')
19
19
  s.add_development_dependency "appraisal"
20
20
  s.add_development_dependency "rake"
21
21
  s.add_development_dependency "rspec"
22
22
  s.add_development_dependency "rspec-core"
23
23
  s.add_development_dependency "pry"
24
24
  s.add_development_dependency "rb-readline"
25
- s.add_development_dependency "sqlite3"
25
+ s.add_development_dependency "sqlite3", "~> 1.3.6"
26
26
  s.add_development_dependency "timecop"
27
27
  s.add_development_dependency "rubocop"
28
28
  s.add_development_dependency "overcommit"
@@ -2,7 +2,8 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "4.2.8"
5
+ gem "rails", "4.2.11.1"
6
6
  gem "nokogiri", "1.6.8.1"
7
+ gem "bundler" , "< 2.0"
7
8
 
8
9
  gemspec path: "../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "5.0.3"
5
+ gem "rails", "5.0.7.2"
6
6
 
7
7
  gemspec path: "../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "5.1"
5
+ gem "rails", "5.1.7"
6
6
 
7
7
  gemspec path: "../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.2.0"
5
+ gem "rails", "~> 5.2.3"
6
6
 
7
7
  gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0.0.rc2"
6
+ gem "sqlite3", "~> 1.4"
7
+
8
+ gemspec path: "../"
data/lib/data_migrate.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2
3
+ if Rails::VERSION::MAJOR == 6
4
+ require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator_five")
5
+ elsif Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2
4
6
  require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator_five")
5
7
  else
6
8
  require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator")
@@ -10,15 +12,22 @@ require File.join(File.dirname(__FILE__), "data_migrate",
10
12
  require File.join(File.dirname(__FILE__), "data_migrate", "data_schema")
11
13
  require File.join(File.dirname(__FILE__), "data_migrate", "database_tasks")
12
14
  require File.join(File.dirname(__FILE__), "data_migrate", "schema_dumper")
13
- if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2
15
+ if Rails::VERSION::MAJOR == 6
16
+ require File.join(File.dirname(__FILE__), "data_migrate", "status_service_five")
17
+ require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_six")
18
+ elsif Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2
14
19
  require File.join(File.dirname(__FILE__), "data_migrate", "status_service_five")
15
20
  require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_five")
16
21
  else
17
22
  require File.join(File.dirname(__FILE__), "data_migrate", "status_service")
18
23
  require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration")
19
24
  end
20
- if Rails::VERSION::MAJOR == 5
21
- if Rails::VERSION::MINOR == 2
25
+
26
+ if Rails::VERSION::MAJOR == 6
27
+ require File.join(File.dirname(__FILE__), "data_migrate", "migration_context")
28
+ # require File.join(File.dirname(__FILE__), "data_migrate", "migration_five")
29
+ elsif Rails::VERSION::MAJOR == 5
30
+ if Rails::VERSION::MINOR == 2
22
31
  require File.join(File.dirname(__FILE__), "data_migrate", "migration_context")
23
32
  else
24
33
  require File.join(File.dirname(__FILE__), "data_migrate", "migration_five")
@@ -20,6 +20,12 @@ module DataMigrate
20
20
  end
21
21
 
22
22
  class << self
23
+ alias_method :migrations_status_orig, :migrations_status
24
+
25
+ def migrations_status
26
+ migrations_status_orig([DataMigrate.config.data_migrations_path])
27
+ end
28
+
23
29
  def current_version(connection = ActiveRecord::Base.connection)
24
30
  get_all_versions(connection).max || 0
25
31
  end
@@ -5,7 +5,9 @@ require "data_migrate/config"
5
5
 
6
6
  module DataMigrate
7
7
  class DataMigrator < ActiveRecord::Migrator
8
- self.migrations_paths = [DataMigrate.config.data_migrations_path]
8
+ def self.migrations_paths
9
+ [DataMigrate.config.data_migrations_path]
10
+ end
9
11
 
10
12
  def self.assure_data_schema_table
11
13
  ActiveRecord::Base.establish_connection(db_config)
@@ -43,6 +45,9 @@ module DataMigrate
43
45
  /(\d{14})_(.+)\.rb/.match(filename)
44
46
  end
45
47
 
48
+ def needs_migration?
49
+ DataMigrate::DatabaseTasks.pending_migrations.count.positive?
50
+ end
46
51
  ##
47
52
  # Provides the full migrations_path filepath
48
53
  # @return (String)
@@ -54,9 +59,10 @@ module DataMigrate
54
59
  DataMigrate::MigrationContext.new(migrations_paths).migrations_status
55
60
  end
56
61
 
57
- #TODO: this was added to be backward compatible, need to re-evaluate
62
+ # TODO: this was added to be backward compatible, need to re-evaluate
58
63
  def migrations(_migrations_paths)
59
- DataMigrate::MigrationContext.new(migrations_paths).migrations
64
+ #DataMigrate::MigrationContext.new(migrations_paths).migrations
65
+ DataMigrate::MigrationContext.new(_migrations_paths).migrations
60
66
  end
61
67
 
62
68
  #TODO: this was added to be backward compatible, need to re-evaluate
@@ -3,7 +3,7 @@ module DataMigrate
3
3
  # to allow data/schema combiation tasks
4
4
  class SchemaMigration
5
5
  def self.pending_schema_migrations
6
- all_migrations = ActiveRecord::MigrationContext.new(migrations_paths).migrations
6
+ all_migrations = DataMigrate::MigrationContext.new(migrations_paths).migrations
7
7
  sort_migrations(
8
8
  ActiveRecord::Migrator.new(:up, all_migrations).
9
9
  pending_migrations.
@@ -0,0 +1,31 @@
1
+ module DataMigrate
2
+ # Helper class to getting access to db schema
3
+ # to allow data/schema combiation tasks
4
+ class SchemaMigration
5
+ def self.pending_schema_migrations
6
+ all_migrations = DataMigrate::MigrationContext.new(migrations_paths).migrations
7
+ sort_migrations(
8
+ ActiveRecord::Migrator.new(:up, all_migrations, ActiveRecord::Base.connection.schema_migration).
9
+ pending_migrations.
10
+ map {|m| { version: m.version, kind: :schema }}
11
+ )
12
+ end
13
+
14
+ def self.run(direction, migration_paths, version)
15
+ ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::Base.connection.schema_migration).run(direction, version)
16
+ end
17
+
18
+ def self.sort_migrations(set1, set2 = nil)
19
+ migrations = set1 + (set2 || [])
20
+ migrations.sort {|a, b| sort_string(a) <=> sort_string(b)}
21
+ end
22
+
23
+ def self.migrations_paths
24
+ Rails.application.config.paths["db/migrate"].to_a
25
+ end
26
+
27
+ def self.sort_string(migration)
28
+ "#{migration[:version]}_#{migration[:kind] == :data ? 1 : 0}"
29
+ end
30
+ end
31
+ end
@@ -9,7 +9,8 @@ module DataMigrate
9
9
  def migrate
10
10
  DataMigrate::DataMigrator.assure_data_schema_table
11
11
  target_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
12
- if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2
12
+ if (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2) ||
13
+ Rails::VERSION::MAJOR == 6
13
14
  DataMigrate::MigrationContext.new(migrations_paths).migrate(target_version)
14
15
  else
15
16
  DataMigrate::DataMigrator.migrate(migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "5.3.2".freeze
2
+ VERSION = "6.0.5".freeze
3
3
  end
@@ -14,7 +14,7 @@ module DataMigrate
14
14
 
15
15
  def create_data_migration
16
16
  set_local_assigns!
17
- migration_template "data_migration.rb", "#{data_migrations_path}#{file_name}.rb"
17
+ migration_template "data_migration.rb", data_migrations_file_path
18
18
  end
19
19
 
20
20
  protected
@@ -36,6 +36,10 @@ module DataMigrate
36
36
  end
37
37
  end
38
38
 
39
+ def data_migrations_file_path
40
+ File.join(data_migrations_path, "#{file_name}.rb")
41
+ end
42
+
39
43
  def data_migrations_path
40
44
  DataMigrate.config.data_migrations_path
41
45
  end
@@ -2,12 +2,13 @@ require "spec_helper"
2
2
 
3
3
  describe DataMigrate::Config do
4
4
 
5
- it "sets default data_migrations_path path" do
5
+ it "sets default data_migrations_path path", :no_override do
6
6
  expect(DataMigrate.config.data_migrations_path).to eq "db/data/"
7
7
  end
8
8
 
9
9
  describe "data migration path configured" do
10
10
  before do
11
+ @before = DataMigrate.config.data_migrations_path
11
12
  DataMigrate.configure do |config|
12
13
  config.data_migrations_path = "db/awesome/"
13
14
  end
@@ -15,7 +16,7 @@ describe DataMigrate::Config do
15
16
 
16
17
  after do
17
18
  DataMigrate.configure do |config|
18
- config.data_migrations_path = "db/data/"
19
+ config.data_migrations_path = @before
19
20
  end
20
21
  end
21
22
 
@@ -9,6 +9,11 @@ describe DataMigrate::DataMigrator do
9
9
  }
10
10
  end
11
11
 
12
+ before do
13
+ allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
14
+ ActiveRecord::Base.establish_connection(db_config)
15
+ end
16
+
12
17
  describe :load_migrated do
13
18
  before do
14
19
  allow(subject).to receive(:db_config) { db_config }.at_least(:once)
@@ -56,6 +61,22 @@ describe DataMigrate::DataMigrator do
56
61
  end
57
62
  end
58
63
 
64
+ describe "#migrations_status" do
65
+ before do
66
+ allow(subject).to receive(:db_config) { db_config }.at_least(:once)
67
+ ActiveRecord::Base.establish_connection(db_config)
68
+ ::ActiveRecord::SchemaMigration.create_table
69
+ DataMigrate::DataSchemaMigration.create_table
70
+ end
71
+
72
+ it "returns all migrations statuses" do
73
+ status = subject.migrations_status
74
+ expect(status.length).to eq 2
75
+ expect(status.first).to eq ["down", "20091231235959", "Some name"]
76
+ expect(status.second).to eq ["down", "20171231235959", "Super update"]
77
+ end
78
+ end
79
+
59
80
  describe :match do
60
81
  context "when the file does not match" do
61
82
  it "returns nil" do
@@ -5,7 +5,9 @@ require "spec_helper"
5
5
  describe DataMigrate::DatabaseTasks do
6
6
  let(:subject) { DataMigrate::DatabaseTasks }
7
7
  let(:migration_path) {
8
- if Rails::VERSION::MAJOR == 5
8
+ if Rails::VERSION::MAJOR == 6
9
+ "spec/db/migrate/6.0"
10
+ elsif Rails::VERSION::MAJOR == 5
9
11
  if Rails::VERSION::MINOR == 2
10
12
  "spec/db/migrate/5.2"
11
13
  else
@@ -16,15 +18,7 @@ describe DataMigrate::DatabaseTasks do
16
18
  end
17
19
  }
18
20
  let(:data_migrations_path) {
19
- if Rails::VERSION::MAJOR == 5
20
- if Rails::VERSION::MINOR == 2
21
- "spec/db/data"
22
- else
23
- "spec/db/5.0"
24
- end
25
- else
26
- "spec/db/4.2"
27
- end
21
+ DataMigrate.config.data_migrations_path
28
22
  }
29
23
  let(:db_config) do
30
24
  {
@@ -2,15 +2,24 @@ require "spec_helper"
2
2
 
3
3
  describe DataMigrate::DataMigrator do
4
4
  let(:context) {
5
- DataMigrate::MigrationContext.new("spec/db/data")
5
+ if (Rails::VERSION::MAJOR == 6)
6
+ DataMigrate::MigrationContext.new("spec/db/data-6.0")
7
+ else
8
+ DataMigrate::MigrationContext.new("spec/db/data")
9
+ end
6
10
  }
7
11
  let(:schema_context) {
8
- ActiveRecord::MigrationContext.new("spec/db/migrate/5.2")
12
+ if (Rails::VERSION::MAJOR == 6)
13
+ ActiveRecord::MigrationContext.new("spec/db/migrate/6.0", ActiveRecord::Base.connection.schema_migration)
14
+ else
15
+ ActiveRecord::MigrationContext.new("spec/db/migrate/5.2")
16
+ end
9
17
  }
10
18
 
11
19
  before do
12
- unless Rails::VERSION::MAJOR == 5 and
13
- Rails::VERSION::MINOR == 2
20
+ unless (Rails::VERSION::MAJOR == 5 and
21
+ Rails::VERSION::MINOR == 2) ||
22
+ Rails::VERSION::MAJOR == 6
14
23
  skip("Tests are only applicable for Rails 5.2")
15
24
  end
16
25
  end
@@ -4,7 +4,9 @@ require "spec_helper"
4
4
 
5
5
  describe DataMigrate::SchemaMigration do
6
6
  let(:migration_path) {
7
- if Rails::VERSION::MAJOR == 5
7
+ if Rails::VERSION::MAJOR == 6
8
+ "spec/db/migrate/6.0"
9
+ elsif Rails::VERSION::MAJOR == 5
8
10
  if Rails::VERSION::MINOR == 2
9
11
  "spec/db/migrate/5.2"
10
12
  else
@@ -46,7 +46,7 @@ describe DataMigrate::StatusService do
46
46
  VALUES #{fixture_file_timestamps.map { |t| "(#{t})" }.join(', ')}
47
47
  SQL
48
48
 
49
- allow_any_instance_of(service).to receive(:root_folder) { "spec" }
49
+ allow_any_instance_of(service).to receive(:root_folder) { "./" }
50
50
  end
51
51
 
52
52
  after do
@@ -11,21 +11,6 @@ describe DataMigrate::Tasks::DataMigrateTasks do
11
11
  end
12
12
 
13
13
  before do
14
- if Rails::VERSION::MAJOR == 5
15
- if Rails::VERSION::MINOR == 2
16
- allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) {
17
- "spec/db/data"
18
- }
19
- else
20
- allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) {
21
- "spec/db/5.0"
22
- }
23
- end
24
- else
25
- allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) {
26
- "spec/db/4.2"
27
- }
28
- end
29
14
  allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
30
15
  ActiveRecord::Base.establish_connection(db_config)
31
16
  end
@@ -36,9 +21,9 @@ describe DataMigrate::Tasks::DataMigrateTasks do
36
21
 
37
22
  describe :migrate do
38
23
  it do
39
- expect {
24
+ expect {
40
25
  DataMigrate::Tasks::DataMigrateTasks.migrate
41
- }.to output(/20091231235959 SomeName: migrating/).to_stdout
26
+ }.to output(/20091231235959 SomeName: migrating/).to_stdout
42
27
  end
43
28
 
44
29
  it do
@@ -1,4 +1,4 @@
1
- class SomeName < ActiveRecord::Migration
1
+ class SomeName < ActiveRecord::Migration[6.0]
2
2
  def up
3
3
  puts "Doing data migration"
4
4
  end
@@ -1,4 +1,4 @@
1
- class SuperUpdate < ActiveRecord::Migration
1
+ class SuperUpdate < ActiveRecord::Migration[6.0]
2
2
  def up
3
3
  puts "Doing data migration"
4
4
  end
@@ -0,0 +1,9 @@
1
+ class SomeName < ActiveRecord::Migration[6.0]
2
+ def up
3
+ puts "Doing data migration"
4
+ end
5
+
6
+ def down
7
+ puts "Undoing SomeName"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class SuperUpdate < ActiveRecord::Migration[6.0]
2
+ def up
3
+ puts "Doing SuperUpdate"
4
+ end
5
+
6
+ def down
7
+ puts "Undoing SuperUpdate"
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ # This file should be excluded
@@ -0,0 +1,9 @@
1
+ class LateMigration < ActiveRecord::Migration[6.0]
2
+ def up
3
+ puts "Doing schema LateMigration"
4
+ end
5
+
6
+ def down
7
+ puts "Undoing LateMigration"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class DbMigration < ActiveRecord::Migration[6.0]
2
+ def up
3
+ puts "Doing schema migration"
4
+ end
5
+
6
+ def down
7
+ puts "Undoing DbMigration"
8
+ end
9
+ end
@@ -24,4 +24,37 @@ describe DataMigrate::Generators::DataMigrationGenerator do
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ describe :create_data_migration do
29
+ let(:subject) { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) }
30
+ let(:data_migrations_file_path) { 'abc/my_migration.rb' }
31
+
32
+ context 'when custom data migrations path has a trailing slash' do
33
+ before do
34
+ DataMigrate.config.data_migrations_path = 'abc/'
35
+ end
36
+
37
+ it 'returns correct file path' do
38
+ expect(subject).to receive(:migration_template).with(
39
+ 'data_migration.rb', data_migrations_file_path
40
+ )
41
+
42
+ subject.create_data_migration
43
+ end
44
+ end
45
+
46
+ context 'when custom data migrations path does not have a trailing slash' do
47
+ before do
48
+ DataMigrate.config.data_migrations_path = 'abc'
49
+ end
50
+
51
+ it 'returns correct file path' do
52
+ expect(subject).to receive(:migration_template).with(
53
+ 'data_migration.rb', data_migrations_file_path
54
+ )
55
+
56
+ subject.create_data_migration
57
+ end
58
+ end
59
+ end
27
60
  end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,37 @@
1
1
  require 'rspec'
2
2
  require 'rails'
3
+ require 'sqlite3'
3
4
  require 'data_migrate'
4
5
  require 'pry'
5
6
  require 'timecop'
6
7
 
7
- if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2
8
- DataMigrate::DataMigrator.migrations_paths = ["spec/db/data"]
9
- end
10
-
11
8
  RSpec.configure do |config|
12
9
  config.mock_with :rspec do |mocks|
13
10
  mocks.verify_partial_doubles = true
14
11
  end
12
+
13
+ config.before(:each) do |example|
14
+ if example.metadata[:no_override]
15
+ else
16
+ if Rails::VERSION::MAJOR == 6
17
+ DataMigrate.configure do |config|
18
+ config.data_migrations_path = "spec/db/6.0"
19
+ end
20
+ elsif Rails::VERSION::MAJOR == 5
21
+ if Rails::VERSION::MINOR == 2
22
+ DataMigrate.configure do |config|
23
+ config.data_migrations_path = "spec/db/data"
24
+ end
25
+ else
26
+ DataMigrate.configure do |config|
27
+ config.data_migrations_path = "spec/db/5.0"
28
+ end
29
+ end
30
+ else
31
+ DataMigrate.configure do |config|
32
+ config.data_migrations_path = "spec/db/5.0"
33
+ end
34
+ end
35
+ end
36
+ end
15
37
  end
data/tasks/databases.rake CHANGED
@@ -194,7 +194,7 @@ namespace :db do
194
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
- ActiveRecord::Migrator.run(:down, "db/migrate/", past_migration[:version])
197
+ DataMigrate::SchemaMigration.run(:down, "db/migrate/", past_migration[:version])
198
198
  end
199
199
  end
200
200
 
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.3.2
4
+ version: 6.0.5
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: 2019-04-01 00:00:00.000000000 Z
13
+ date: 2019-10-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '4.2'
21
+ version: '5.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '4.2'
28
+ version: '5.0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: appraisal
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -114,16 +114,16 @@ dependencies:
114
114
  name: sqlite3
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - ">="
117
+ - - "~>"
118
118
  - !ruby/object:Gem::Version
119
- version: '0'
119
+ version: 1.3.6
120
120
  type: :development
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - ">="
124
+ - - "~>"
125
125
  - !ruby/object:Gem::Version
126
- version: '0'
126
+ version: 1.3.6
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: timecop
129
129
  requirement: !ruby/object:Gem::Requirement
@@ -178,9 +178,11 @@ files:
178
178
  - ".gitignore"
179
179
  - ".hound.yml"
180
180
  - ".overcommit.yml"
181
+ - ".rbenv-gemsets"
181
182
  - ".rspec"
182
183
  - ".rubocop.yml"
183
184
  - ".ruby-style.yml"
185
+ - ".ruby-version"
184
186
  - ".travis.yml"
185
187
  - Appraisals
186
188
  - Changelog.md
@@ -197,6 +199,7 @@ files:
197
199
  - gemfiles/rails_5.0.gemfile
198
200
  - gemfiles/rails_5.1.gemfile
199
201
  - gemfiles/rails_5.2.gemfile
202
+ - gemfiles/rails_6.0.gemfile
200
203
  - lib/capistrano/data_migrate.rb
201
204
  - lib/capistrano/data_migrate/migrate.rb
202
205
  - lib/data_migrate.rb
@@ -214,6 +217,7 @@ files:
214
217
  - lib/data_migrate/schema_dumper.rb
215
218
  - lib/data_migrate/schema_migration.rb
216
219
  - lib/data_migrate/schema_migration_five.rb
220
+ - lib/data_migrate/schema_migration_six.rb
217
221
  - lib/data_migrate/status_service.rb
218
222
  - lib/data_migrate/status_service_five.rb
219
223
  - lib/data_migrate/tasks/data_migrate_tasks.rb
@@ -235,10 +239,13 @@ files:
235
239
  - spec/data_migrate/schema_migration_spec.rb
236
240
  - spec/data_migrate/status_service_spec.rb
237
241
  - spec/data_migrate/tasks/data_migrate_tasks_spec.rb
238
- - spec/db/4.2/20091231235959_some_name.rb
239
- - spec/db/4.2/20171231235959_super_update.rb
240
242
  - spec/db/5.0/20091231235959_some_name.rb
241
243
  - spec/db/5.0/20171231235959_super_update.rb
244
+ - spec/db/6.0/20091231235959_some_name.rb
245
+ - spec/db/6.0/20171231235959_super_update.rb
246
+ - spec/db/data-6.0/20091231235959_some_name.rb
247
+ - spec/db/data-6.0/20171231235959_super_update.rb
248
+ - spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext
242
249
  - spec/db/data/20091231235959_some_name.rb
243
250
  - spec/db/data/20171231235959_super_update.rb
244
251
  - spec/db/data/20181128000207_excluded_file.rb.other_ext
@@ -248,6 +255,8 @@ files:
248
255
  - spec/db/migrate/5.0/20202020202011_db_migration.rb
249
256
  - spec/db/migrate/5.2/20131111111111_late_migration.rb
250
257
  - spec/db/migrate/5.2/20202020202011_db_migration.rb
258
+ - spec/db/migrate/6.0/20131111111111_late_migration.rb
259
+ - spec/db/migrate/6.0/20202020202011_db_migration.rb
251
260
  - spec/generators/data_migration/data_migration_generator_spec.rb
252
261
  - spec/spec_helper.rb
253
262
  - tasks/.gitkeep
@@ -277,8 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
286
  - !ruby/object:Gem::Version
278
287
  version: '0'
279
288
  requirements: []
280
- rubyforge_project: data_migrate
281
- rubygems_version: 2.7.8
289
+ rubygems_version: 3.0.1
282
290
  signing_key:
283
291
  specification_version: 4
284
292
  summary: Rake tasks to migrate data alongside schema changes.
@@ -295,10 +303,13 @@ test_files:
295
303
  - spec/data_migrate/schema_migration_spec.rb
296
304
  - spec/data_migrate/status_service_spec.rb
297
305
  - spec/data_migrate/tasks/data_migrate_tasks_spec.rb
298
- - spec/db/4.2/20091231235959_some_name.rb
299
- - spec/db/4.2/20171231235959_super_update.rb
300
306
  - spec/db/5.0/20091231235959_some_name.rb
301
307
  - spec/db/5.0/20171231235959_super_update.rb
308
+ - spec/db/6.0/20091231235959_some_name.rb
309
+ - spec/db/6.0/20171231235959_super_update.rb
310
+ - spec/db/data-6.0/20091231235959_some_name.rb
311
+ - spec/db/data-6.0/20171231235959_super_update.rb
312
+ - spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext
302
313
  - spec/db/data/20091231235959_some_name.rb
303
314
  - spec/db/data/20171231235959_super_update.rb
304
315
  - spec/db/data/20181128000207_excluded_file.rb.other_ext
@@ -308,5 +319,7 @@ test_files:
308
319
  - spec/db/migrate/5.0/20202020202011_db_migration.rb
309
320
  - spec/db/migrate/5.2/20131111111111_late_migration.rb
310
321
  - spec/db/migrate/5.2/20202020202011_db_migration.rb
322
+ - spec/db/migrate/6.0/20131111111111_late_migration.rb
323
+ - spec/db/migrate/6.0/20202020202011_db_migration.rb
311
324
  - spec/generators/data_migration/data_migration_generator_spec.rb
312
325
  - spec/spec_helper.rb