data_migrate 5.1.0 → 6.0.4.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  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 +39 -3
  7. data/Gemfile +2 -0
  8. data/Gemfile.rails5.1 +1 -1
  9. data/README.md +30 -18
  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/capistrano/data_migrate/migrate.rb +3 -4
  17. data/lib/data_migrate.rb +14 -10
  18. data/lib/data_migrate/config.rb +21 -0
  19. data/lib/data_migrate/data_migrator.rb +20 -14
  20. data/lib/data_migrate/data_migrator_five.rb +7 -3
  21. data/lib/data_migrate/database_tasks.rb +3 -1
  22. data/lib/data_migrate/schema_migration_five.rb +1 -1
  23. data/lib/data_migrate/schema_migration_six.rb +31 -0
  24. data/lib/data_migrate/status_service.rb +1 -1
  25. data/lib/data_migrate/tasks/data_migrate_tasks.rb +4 -8
  26. data/lib/data_migrate/version.rb +1 -1
  27. data/lib/generators/data_migration/data_migration_generator.rb +10 -1
  28. data/spec/data_migrate/config_spec.rb +27 -0
  29. data/spec/data_migrate/data_migrator_spec.rb +21 -0
  30. data/spec/data_migrate/database_tasks_spec.rb +4 -10
  31. data/spec/data_migrate/migration_context_spec.rb +13 -4
  32. data/spec/data_migrate/schema_migration_spec.rb +3 -1
  33. data/spec/data_migrate/status_service_spec.rb +10 -1
  34. data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +2 -17
  35. data/spec/db/{4.2 → 6.0}/20091231235959_some_name.rb +1 -1
  36. data/spec/db/{4.2 → 6.0}/20171231235959_super_update.rb +1 -1
  37. data/spec/db/data-6.0/20091231235959_some_name.rb +9 -0
  38. data/spec/db/data-6.0/20171231235959_super_update.rb +9 -0
  39. data/spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext +1 -0
  40. data/spec/db/data/20181128000207_excluded_file.rb.other_ext +1 -0
  41. data/spec/db/migrate/6.0/20131111111111_late_migration.rb +9 -0
  42. data/spec/db/migrate/6.0/20202020202011_db_migration.rb +9 -0
  43. data/spec/generators/data_migration/data_migration_generator_spec.rb +33 -0
  44. data/spec/spec_helper.rb +26 -4
  45. data/tasks/databases.rake +14 -10
  46. metadata +34 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 374e93835d9a65e56af9ce534dd650c286a3dbcf
4
- data.tar.gz: 48a7b7a1b7870b28f4cc34bff8468cc797649c8d
2
+ SHA256:
3
+ metadata.gz: 04d7f1a511de2b5d2fa39aeb5bbeeb2786e916c92ad3cc1b6252e5f3fc2ed5d2
4
+ data.tar.gz: 9a7d2d4f9fef7fbd193d63844058cab15716387d595f52acd52d552a20f73a1d
5
5
  SHA512:
6
- metadata.gz: 3b53c608118790f93587e29221f7d5aad40fcbe782f081f314d3955228f6ad45f2fbe90b565221aeb90fb38fe6642883f850b31ae7ec8d925b7b34c7a07cc2b7
7
- data.tar.gz: 1500d7f084fcdc4b8f0a442925a695c90b495a148da5ba6021add79d432c8826c6bc2b965bc178595796d92fe8d990f931860f02e0fadcc68674546e366bf2bf
6
+ metadata.gz: abf2884ae3a915dd7a1ee357df76b4844d164e8e861404781b686fcdca9cedef37b8c82a401d42d56b1eb91033927fd23aaa7834699dc5e1e1fa4a40b408ac63
7
+ data.tar.gz: 36508cb78ecc4146671582e8db6ddd056e088d1b942b6aba7f78427e2ac453e749bdd18341b93b058ce580331e03ec18363d05bc2497fa7fa4e906cb0bba9183
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,7 +1,39 @@
1
- Changelog
2
- =========
1
+ # Changelog
2
+
3
+ ## 6.0.4.beta
4
+ Fix rolling back schema migrations failing for Rails 5.2 and above
5
+
6
+ ## 6.0.3.beta
7
+
8
+ Compatiblity with Rails 6 RC2 [y-yagi](https://github.com/y-yagi)
9
+
10
+ ## 6.0.1.beta
11
+
12
+ Fix migrations being generated in wrong folder
13
+
14
+ ## 6.0.0
15
+
16
+ Support for Rails 6
17
+ No longer supporting Rails 4.2
18
+
19
+ ## 5.3.3
20
+
21
+ Ruby 2.2 and 2.3 are no longer actively validated with tests since they are both EOL
22
+
23
+ ## 5.3.2
24
+
25
+ Fix capistrano migration tasks to only skip migrations if there are no changes in the db/data and db/migrate folders
26
+
27
+ ## 5.3.1
28
+
29
+ Change database task to use data_migrations_path_configuration
30
+
31
+ ## 5.3.0
32
+
33
+ Add support to configure data migration path
3
34
 
4
35
  ## 5.1.0
36
+
5
37
  Fixes to `db:schema:load:with_data` + `db:structure:load:with_data` definition, thanks to [craineum](https://github.com/craineum)
6
38
 
7
39
  ## 5.0.0
@@ -28,11 +60,15 @@ Deprecated support for rails 4.0
28
60
  Improvements to timestamped migrations, thanks to [Pierre-Michard](https://github.com/Pierre-Michard)
29
61
 
30
62
  ## 3.4.0
63
+
31
64
  `rake data:migrate:status` to return result in chronological order
65
+
32
66
  ## 3.3.1
67
+
33
68
  Regression fix, thanks to [subakva](https://github.com/subakva)
34
69
 
35
70
  ## 3.3.0
71
+
36
72
  The concept of schema:dump to data migrations, thanks to
37
73
  [tobyndockerill](https://github.com/tobyndockerill)
38
74
 
@@ -41,8 +77,8 @@ The concept of schema:dump to data migrations, thanks to
41
77
  data_migrate table into rails schema dump, thanks to
42
78
  [jturkel](https://github.com/jturkel)
43
79
 
44
-
45
80
  ## 3.2.0
81
+
46
82
  - Add support for Rails 5.1
47
83
  - No longer testing EOL rubies
48
84
 
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,10 +1,9 @@
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
8
  Run data migrations alongside schema migrations.
10
9
 
@@ -18,13 +17,13 @@ is the place to do it.
18
17
  # Why should I use this?
19
18
 
20
19
  Its seems when a project hits a certain size, I get to manipulate data
21
- outside the application itself. Changing defaults, new validations,
20
+ outside the application itself. Changing defaults, new validations,
22
21
  one-to-one to one-to-many... I found it a pain and dodgy to have to
23
22
  step up migrations one by one, run a ruby script of some sort, then
24
- resume migrations. It tanks a lot of the automation of deploy.
23
+ resume migrations. It tanks a lot of the automation of deploy.
25
24
 
26
25
  If you don't use the one off scripts, you could do it as a regular
27
- 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
28
27
  of having them separate has to do with your data model.
29
28
 
30
29
  For instance, lets take an absurd example, to illustrate: You have
@@ -33,28 +32,29 @@ After some use, you decide you are going to be a trend setter,
33
32
  and want only one comment per post, and just the text.
34
33
 
35
34
  Given that you:
35
+
36
36
  - write a migration to add a comment column to `Post`
37
37
  - write a migration to move the contents of the first comments to the `Post`
38
38
  - drop the `column_id` column from `Post`
39
39
  - drop the `Comment` model
40
40
  - fix all your tests
41
41
 
42
- 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
43
43
  mad at you after it creates your database, and starts cranking through
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
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
47
47
  ActiveRecord call in a conditional based on the environment.
48
48
 
49
49
  That's fine until you get that QA gal, and she wants her own thing.
50
50
  Then the UI people get tired of waiting for the full stack to load on page
51
51
  refreshes, so you have to edit past migrations...
52
52
 
53
- With Data Migrate, you have the control. You can generate your
53
+ With Data Migrate, you have the control. You can generate your
54
54
  migrations as schema or data as you would as your work flow. For
55
55
  setting tasks that don't require any intermediate AR activity, like
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
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
58
58
  test your migration, so you have the choice of `db:migrate:with_data` or
59
59
  `data:migrate` to just capture that data change.
60
60
 
@@ -69,7 +69,7 @@ table to track all the goodness.
69
69
 
70
70
  ## Rails Support
71
71
 
72
- Support Rails 4.2 through 5.2
72
+ Support Rails 5.0 through 6.0
73
73
 
74
74
  ### Important notes for older versions
75
75
 
@@ -92,6 +92,7 @@ If you've installed previous to v1.1.0, you'll want to delete the
92
92
  `create_data_migrations_table` migration.
93
93
 
94
94
  ## Installation
95
+
95
96
  Add the gem to your project
96
97
 
97
98
  # Gemfile
@@ -103,7 +104,6 @@ So you know, when you use one of the provide rake tasks, a table
103
104
  called `data_migrations` will be created in your database. This
104
105
  is to mirror the way the standard `db` rake tasks work.
105
106
 
106
-
107
107
  ## Usage
108
108
 
109
109
  ### Generating Migrations
@@ -137,13 +137,24 @@ You can generate a data migration as you would a schema migration:
137
137
 
138
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.
139
139
 
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.
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.
141
141
 
142
142
  `rake db:migrate:status:with_data` provides and additional column to indicate which type of migration.
143
+
143
144
  ### Configuration
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
+ By default, data migrations are added to the `db/data/` path.
149
+ You can override this setting in `config/initializers/data_migrate.rb`
150
+
151
+ ```ruby
152
+ DataMigrate.configure do |config|
153
+ config.data_migrations_path = "db/awesomepath/"
154
+ end
155
+
156
+ ```
157
+
147
158
  ## Capistrano Support
148
159
 
149
160
  The gem comes with a capistrano task that can be used instead of `capistrano/rails/migrations`.
@@ -164,13 +175,14 @@ Run tests for a specific version of Rails
164
175
 
165
176
  ```
166
177
  bundle exec appraisal install
167
- bundle exec appraisal rails-4.2 rspec
168
178
  bundle exec appraisal rails-5.0 rspec
179
+ bundle exec appraisal rails-5.2 rspec
169
180
  ```
170
181
 
171
182
  ## Thanks
183
+
172
184
  [Andrew J Vargo](http://github.com/ajvargo) Andrew was the original creator and maintainer of this project!
173
185
 
174
186
  [Jeremy Durham](http://jeremydurham.com/) for fleshing out the idea with me, and providing guidance.
175
187
 
176
- 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: "../"
@@ -7,10 +7,9 @@ namespace :deploy do
7
7
  conditionally_migrate = fetch(:conditionally_migrate)
8
8
  info '[deploy:migrate] Checking changes in db/migrate or db/data' if conditionally_migrate
9
9
 
10
- if conditionally_migrate && (
11
- test("diff -q #{release_path}/db/migrate #{current_path}/db/migrate") ||
12
- test("diff -q #{release_path}/db/data #{current_path}/db/data")
13
- )
10
+ if conditionally_migrate &&
11
+ test("diff -q #{release_path}/db/migrate #{current_path}/db/migrate") &&
12
+ test("diff -q #{release_path}/db/data #{current_path}/db/data")
14
13
  info '[deploy:migrate] Skip `deploy:migrate` (nothing changed in db/migrate or db/data)'
15
14
  else
16
15
  info '[deploy:migrate] Run `rake db:migrate:with_data`'
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")
@@ -29,12 +38,7 @@ end
29
38
  require File.join(File.dirname(__FILE__), "data_migrate", "railtie")
30
39
  require File.join(File.dirname(__FILE__), "data_migrate", "tasks/data_migrate_tasks")
31
40
  require File.join(File.dirname(__FILE__), "data_migrate", "legacy_migrator")
41
+ require File.join(File.dirname(__FILE__), "data_migrate", "config")
32
42
 
33
43
  module DataMigrate
34
- include ActiveSupport::Configurable
35
- class << self
36
- def configure
37
- yield config
38
- end
39
- end
40
44
  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
@@ -3,16 +3,15 @@
3
3
  require "active_record"
4
4
 
5
5
  module DataMigrate
6
-
7
6
  class DataMigrator < ActiveRecord::Migrator
8
7
 
9
8
  def record_version_state_after_migrating(version)
10
9
  if down?
11
10
  migrated.delete(version)
12
- DataMigrate::DataSchemaMigration.where(:version => version.to_s).delete_all
11
+ DataMigrate::DataSchemaMigration.where(version: version.to_s).delete_all
13
12
  else
14
13
  migrated << version
15
- DataMigrate::DataSchemaMigration.create!(:version => version.to_s)
14
+ DataMigrate::DataSchemaMigration.create!(version: version.to_s)
16
15
  end
17
16
  end
18
17
 
@@ -21,6 +20,12 @@ module DataMigrate
21
20
  end
22
21
 
23
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
+
24
29
  def current_version(connection = ActiveRecord::Base.connection)
25
30
  get_all_versions(connection).max || 0
26
31
  end
@@ -39,7 +44,7 @@ module DataMigrate
39
44
  end
40
45
 
41
46
  def migrations_path
42
- "db/data"
47
+ DataMigrate.config.data_migrations_path
43
48
  end
44
49
 
45
50
  ##
@@ -64,23 +69,24 @@ module DataMigrate
64
69
  # @param (String) filename
65
70
  # @return (MatchData)
66
71
  def match(filename)
67
- /(\d{14})_(.+)\.rb/.match(filename)
72
+ /(\d{14})_(.+)\.rb$/.match(filename)
68
73
  end
69
74
 
70
75
  private
71
76
 
72
77
  def create_table(sm_table)
73
- ActiveRecord::Base.connection.create_table(sm_table, :id => false) do |schema_migrations_table|
74
- schema_migrations_table.column :version, :string, :null => false
75
- end
78
+ ActiveRecord::Base.connection.create_table(sm_table, id: false) do |schema_migrations_table|
79
+ schema_migrations_table.column :version, :string, null: false
80
+ end
81
+
82
+ suffix = ActiveRecord::Base.table_name_suffix
83
+ prefix = ActiveRecord::Base.table_name_prefix
84
+ index_name = "#{prefix}unique_data_migrations#{suffix}"
76
85
 
77
- suffix = ActiveRecord::Base.table_name_suffix
78
- prefix = ActiveRecord::Base.table_name_prefix
79
- index_name = "#{prefix}unique_data_migrations#{suffix}"
86
+ options = {unique: true, name: index_name}
87
+ options[:length] = 191 if ActiveRecord::Base.connection_config[:adapter] == "mysql2"
80
88
 
81
- ActiveRecord::Base.connection.add_index sm_table, :version,
82
- :unique => true,
83
- :name => index_name
89
+ ActiveRecord::Base.connection.add_index sm_table, :version, options
84
90
  end
85
91
 
86
92
  def table_exists?(connection, table_name)