data_migrate 8.1.1 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog.md +100 -0
- data/README.md +42 -8
- data/lib/data_migrate/config.rb +11 -1
- data/lib/data_migrate/{data_migrator_five.rb → data_migrator.rb} +15 -35
- data/lib/data_migrate/data_schema.rb +8 -8
- data/lib/data_migrate/data_schema_migration.rb +21 -5
- data/lib/data_migrate/database_configurations_wrapper.rb +11 -0
- data/lib/data_migrate/database_tasks.rb +233 -69
- data/lib/data_migrate/migration_context.rb +11 -8
- data/lib/data_migrate/rails_helper.rb +91 -0
- data/lib/data_migrate/schema_dumper.rb +1 -1
- data/lib/data_migrate/{schema_migration_six.rb → schema_migration.rb} +7 -4
- data/lib/data_migrate/{status_service_five.rb → status_service.rb} +14 -8
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +24 -43
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +8 -9
- data/lib/generators/data_migrate.rb +15 -2
- data/lib/generators/data_migration/data_migration_generator.rb +7 -2
- data/tasks/databases.rake +36 -121
- metadata +19 -77
- data/.github/workflows/gempush.yml +0 -29
- data/.gitignore +0 -11
- data/.hound.yml +0 -4
- data/.overcommit.yml +0 -21
- data/.rbenv-gemsets +0 -2
- data/.rspec +0 -3
- data/.rubocop.yml +0 -2
- data/.ruby-style.yml +0 -1061
- data/.ruby-version +0 -1
- data/.travis.yml +0 -14
- data/Appraisals +0 -15
- data/Gemfile +0 -4
- data/Gemfile.rails5.2 +0 -10
- data/Gemfile.rails6.1 +0 -11
- data/Rakefile +0 -2
- data/data_migrate.gemspec +0 -50
- data/gemfiles/rails_5.2.gemfile +0 -8
- data/gemfiles/rails_6.0.gemfile +0 -8
- data/gemfiles/rails_6.1.gemfile +0 -8
- data/gemfiles/rails_7.0.gemfile +0 -8
- data/lib/data_migrate/legacy_migrator.rb +0 -22
- data/lib/data_migrate/schema_migration_five.rb +0 -31
- data/screenshot.png +0 -0
- data/spec/data_migrate/config_spec.rb +0 -27
- data/spec/data_migrate/data_migrator_spec.rb +0 -101
- data/spec/data_migrate/data_schema_migration_spec.rb +0 -16
- data/spec/data_migrate/data_spec.rb +0 -85
- data/spec/data_migrate/database_tasks_spec.rb +0 -138
- data/spec/data_migrate/legacy_migrator_spec.rb +0 -50
- data/spec/data_migrate/migration.rb +0 -19
- data/spec/data_migrate/migration_context_spec.rb +0 -127
- data/spec/data_migrate/schema_dumper_spec.rb +0 -46
- data/spec/data_migrate/schema_migration_spec.rb +0 -99
- data/spec/data_migrate/status_service_spec.rb +0 -102
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +0 -164
- data/spec/db/6.0/20091231235959_some_name.rb +0 -9
- data/spec/db/6.0/20171231235959_super_update.rb +0 -9
- data/spec/db/data/20091231235959_some_name.rb +0 -9
- data/spec/db/data/20171231235959_super_update.rb +0 -9
- data/spec/db/data/20181128000207_excluded_file.rb.other_ext +0 -1
- data/spec/db/data/partial_schema/data_schema.rb +0 -1
- data/spec/db/data/partial_schema/test_data_schema.rb +0 -1
- data/spec/db/data/schema/data_schema.rb +0 -1
- data/spec/db/data/schema/test_data_schema.rb +0 -1
- data/spec/db/data-6.0/20091231235959_some_name.rb +0 -9
- data/spec/db/data-6.0/20171231235959_super_update.rb +0 -9
- data/spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext +0 -1
- data/spec/db/migrate/5.2/20131111111111_late_migration.rb +0 -9
- data/spec/db/migrate/5.2/20202020202011_db_migration.rb +0 -9
- data/spec/db/migrate/6.0/20131111111111_late_migration.rb +0 -9
- data/spec/db/migrate/6.0/20202020202011_db_migration.rb +0 -9
- data/spec/generators/data_migration/data_migration_generator_spec.rb +0 -60
- data/spec/spec_helper.rb +0 -34
- data/tasks/.gitkeep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20f45c0a409f5eea659d56b8118d9625e3358cdd9d199978b56359d3416abe64
|
4
|
+
data.tar.gz: f553fd264b97b71671556ece98e9c79830223e960e7f41a46e383587a7b728c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ac579c9ca5323c12e413f4c2ad228f9f36cbeb7d84624ff6fa24160f350b5e91f3ca7a8f18e469ce8e25dd4390a9d76316f40257dd9ef5bf4324c60309dd55f
|
7
|
+
data.tar.gz: f2fe12d32734ba839ce736d6634d2e794aad151b2719ff6e4a9bf1c9a05ccfdc4ab2a2de6bed8636a9423e89d6dddf62442ccf2f4c91ede15cf66736f36ff64f
|
data/Changelog.md
CHANGED
@@ -1,5 +1,105 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 11.3.0
|
4
|
+
- Make table_name configurable https://github.com/ilyakatz/data-migrate/pull/361
|
5
|
+
- Use lease_connection over deprecated connection for rails 8 https://github.com/ilyakatz/data-migrate/pull/353
|
6
|
+
- Add Ruby 3.4 to CI matrix
|
7
|
+
|
8
|
+
# 11.2.0
|
9
|
+
- Remove committed Gemfile.lock, reduce bundled file list when running `gem install` https://github.com/ilyakatz/data-migrate/pull/351
|
10
|
+
- [Bump actionpack from 7.1.3.4 to 7.1.4.1](https://github.com/ilyakatz/data-migrate/pull/348)
|
11
|
+
- [Bump rexml from 3.3.6 to 3.3.9](https://github.com/ilyakatz/data-migrate/pull/349)
|
12
|
+
- Fix db_config_with_versions arity change and backport https://github.com/ilyakatz/data-migrate/pull/337
|
13
|
+
|
14
|
+
# 11.1.0
|
15
|
+
- Allow multiple data migration paths https://github.com/ilyakatz/data-migrate/pull/331
|
16
|
+
- Fix db:prepare:with_data task on [Rails 7.2](https://github.com/ilyakatz/data-migrate/pull/339)
|
17
|
+
- Fix ConnectionPool deprecation warnings on [Rails 7.2](https://github.com/ilyakatz/data-migrate/pull/341)
|
18
|
+
- Add Rails 8.0 to testing grounds https://github.com/ilyakatz/data-migrate/pull/341
|
19
|
+
- [Bump webrick from 1.8.1 to 1.8.2](https://github.com/ilyakatz/data-migrate/pull/345)
|
20
|
+
|
21
|
+
# 11.0.0
|
22
|
+
- [Update rexml to 3.3.6](https://github.com/ilyakatz/data-migrate/pull/329)
|
23
|
+
- Fixes a bug which ignored migrations on [Rails 7.1 and higher](https://github.com/ilyakatz/data-migrate/pull/326)
|
24
|
+
|
25
|
+
# 11.0.0rc
|
26
|
+
- Remove Ruby 3.0 from build matrix
|
27
|
+
- Support Rails 7.2.0 https://github.com/ilyakatz/data-migrate/pull/312
|
28
|
+
- Update gemfile.lock builds
|
29
|
+
|
30
|
+
## 9.4.2
|
31
|
+
- Fix db:prepare:with_data task
|
32
|
+
|
33
|
+
## 9.4.1
|
34
|
+
- Add db:prepare task
|
35
|
+
|
36
|
+
## 9.4.0
|
37
|
+
- Reset model schema cache before each data migration https://github.com/ilyakatz/data-migrate/pull/307
|
38
|
+
- Run load_config rake task before db:migrate:with_data https://github.com/ilyakatz/data-migrate/pull/308
|
39
|
+
|
40
|
+
## 9.3.0
|
41
|
+
- Improve with_data Rake task for multiple database https://github.com/ilyakatz/data-migrate/pull/296
|
42
|
+
|
43
|
+
## 9.2.0
|
44
|
+
- Support Rails 7.1 https://github.com/ilyakatz/data-migrate/pull/278
|
45
|
+
- Build and test against 7.1.0.rc1 https://github.com/ilyakatz/data-migrate/pull/286
|
46
|
+
|
47
|
+
## 9.1.0
|
48
|
+
|
49
|
+
- Fix a bug that caused `schema_sha1` in `ar_internal_metadata` to be reset to the `data_schema.rb` file. (#272)
|
50
|
+
- Remove the need for empty data_schema files for non-primary databases. (#273)
|
51
|
+
|
52
|
+
## [YANKED] 10.0.3.rc
|
53
|
+
|
54
|
+
- Remove all travis references [leoarnold](https//:github.com/leoarnold)
|
55
|
+
- Changing to rc because of ongoing discussion how to properly handle multiple database environments
|
56
|
+
|
57
|
+
## [YANKED] 10.0.2
|
58
|
+
|
59
|
+
Change "rails" dependencies to "railties"
|
60
|
+
|
61
|
+
## [YANKED] 10.0.1
|
62
|
+
|
63
|
+
- Bug fix for Rails 6 config [chaunce](https//:github.com/chaunce)
|
64
|
+
- Railties bug fix by [opti](https://github.com/opti)
|
65
|
+
|
66
|
+
## [YANKED] 10.0.0
|
67
|
+
|
68
|
+
Releasing 10.0.0
|
69
|
+
|
70
|
+
!!! Breaking changes !!!
|
71
|
+
|
72
|
+
- This version introduces a breaking change which may lead to undesired
|
73
|
+
behavior in multi-database environments. See https://github.com/ilyakatz/data-migrate/issues/181
|
74
|
+
|
75
|
+
## [YANKED] 10.0.0.rc1
|
76
|
+
|
77
|
+
- Changes by [chaunce](https//:github.com/chaunce)
|
78
|
+
- Multiple databases support
|
79
|
+
- Refactor to clean things up
|
80
|
+
- Deprecate rails 5.2 support for real
|
81
|
+
|
82
|
+
## 9.0.0
|
83
|
+
|
84
|
+
Ruby 3.2 support [mehanoid](https://github.com/mehanoid)
|
85
|
+
Rails 5.2 is no longer supported
|
86
|
+
|
87
|
+
## 8.5.0
|
88
|
+
|
89
|
+
Allow custom templates [bazay](https://github.com/bazay)
|
90
|
+
|
91
|
+
## 8.4.0
|
92
|
+
|
93
|
+
Avoid Globally Accessible Functions for All Rake Tasks [berniechiu](https://github.com/berniechiu)
|
94
|
+
|
95
|
+
## 8.3.0
|
96
|
+
|
97
|
+
Add delegation to exists? for use by third parties [foxondo](https://github.com/foxondo)
|
98
|
+
|
99
|
+
## 8.2.0
|
100
|
+
|
101
|
+
Delegate to anonymous subclass of AR::SchemaMigration [foxondo](https://github.com/foxondo)
|
102
|
+
|
3
103
|
## 8.1.1
|
4
104
|
|
5
105
|
Revert 8.1.0 changes
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
- [](https://rubygems.org/gems/data_migrate)
|
4
4
|
- [](http://opensource.org/licenses/MIT)
|
5
|
-
-
|
5
|
+
- 
|
6
6
|
- [](https://houndci.com)
|
7
7
|
|
8
8
|
Run data migrations alongside schema migrations.
|
@@ -12,7 +12,7 @@ migrations, except they should be reserved for data migrations. For
|
|
12
12
|
instance, if you realize you need to titleize all your titles, this
|
13
13
|
is the place to do it.
|
14
14
|
|
15
|
-

|
16
16
|
|
17
17
|
## Why should I use this?
|
18
18
|
|
@@ -36,8 +36,13 @@ table to track all migrations.
|
|
36
36
|
|
37
37
|
## Rails Support
|
38
38
|
|
39
|
-
Support Rails
|
39
|
+
Support Rails 6.1 through 8.0
|
40
40
|
|
41
|
+
For **Rails 6.0** support, please use gem version `9.1.x`:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
gem 'data_migrate', '~> 9.1.0'
|
45
|
+
```
|
41
46
|
|
42
47
|
#### v1
|
43
48
|
|
@@ -86,6 +91,7 @@ You can generate a data migration as you would a schema migration:
|
|
86
91
|
rake db:migrate:status:with_data # Display status of data and schema migrations
|
87
92
|
rake db:migrate:up:with_data # Runs the "up" for a given migration VERSION
|
88
93
|
rake db:migrate:with_data # Migrate the database data and schema (options: VERSION=x, VERBOSE=false)
|
94
|
+
rake db:prepare:with_data # Runs setup if database does not exist, or runs data and schema migrations if it does
|
89
95
|
rake db:rollback:with_data # Rolls the schema back to the previous version (specify steps w/ STEP=n)
|
90
96
|
rake db:schema:load:with_data # Load both schema.rb and data_schema.rb file into the database
|
91
97
|
rake db:structure:load:with_data # Load both structure.sql and data_schema.rb file into the database
|
@@ -96,7 +102,9 @@ Tasks work as they would with the 'vanilla' db version. The 'with_data' addition
|
|
96
102
|
|
97
103
|
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.
|
98
104
|
|
99
|
-
`rake db:migrate:
|
105
|
+
When using `rake db:migrate:with_data` migrations will be run in ascending order by their version. For example, if you have a data migration with version 20230410000000 and a schema migration with version 20230415000000, expect the data migration to run first.
|
106
|
+
|
107
|
+
`rake db:migrate:status:with_data` provides an additional column to indicate which type of migration.
|
100
108
|
|
101
109
|
### Configuration
|
102
110
|
|
@@ -107,7 +115,9 @@ You can override this setting in `config/initializers/data_migrate.rb`
|
|
107
115
|
|
108
116
|
```ruby
|
109
117
|
DataMigrate.configure do |config|
|
118
|
+
config.data_migrations_table_name = 'my_migrations_database_name'
|
110
119
|
config.data_migrations_path = 'db/awesomepath/'
|
120
|
+
config.data_template_path = Rails.root.join("lib", "awesomepath", "custom_data_migration.rb")
|
111
121
|
config.db_configuration = {
|
112
122
|
'host' => '127.0.0.1',
|
113
123
|
'database' => 'awesome_database',
|
@@ -132,6 +142,20 @@ require 'capistrano/data_migrate'
|
|
132
142
|
|
133
143
|
From now on capistrano will run `rake db:migrate:with_data` in every deploy.
|
134
144
|
|
145
|
+
## Rails Engines support
|
146
|
+
|
147
|
+
This gem also has a initial support for adding data migrations inside Rails engines.
|
148
|
+
Just add your engines directory pattern to data_migrations initializer, for example
|
149
|
+
in the case your engines are located in `engines` folder you can set it up like this:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
DataMigrate.configure do |config|
|
153
|
+
config.data_migrations_path = ['db/data'] + Dir['engines/**/db/data']
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
Then, in the Engine's `db/data` folder, you can add data migrations and run them as usual.
|
158
|
+
|
135
159
|
### Contributing
|
136
160
|
|
137
161
|
## Testing
|
@@ -139,12 +163,22 @@ From now on capistrano will run `rake db:migrate:with_data` in every deploy.
|
|
139
163
|
Run tests for a specific version of Rails
|
140
164
|
|
141
165
|
```
|
142
|
-
bundle exec appraisal
|
143
|
-
bundle exec appraisal rails-
|
144
|
-
bundle exec appraisal rails-
|
145
|
-
bundle exec appraisal rails-
|
166
|
+
bundle exec appraisal rails-6.1 rspec
|
167
|
+
bundle exec appraisal rails-7.0 rspec
|
168
|
+
bundle exec appraisal rails-7.1 rspec
|
169
|
+
bundle exec appraisal rails-7.2 rspec
|
170
|
+
bundle exec appraisal rails-8.0 rspec
|
146
171
|
```
|
147
172
|
|
173
|
+
## Releasing new version
|
174
|
+
|
175
|
+
1. Update version.rb file, run `bundle exec appraisal` to update the version in corresponding gemfile.lock
|
176
|
+
2. Create a new tag, eg `git tag 9.4.1`
|
177
|
+
3. Go to https://github.com/ilyakatz/data-migrate/tags
|
178
|
+
4. Click "Create release" under 9.4.1
|
179
|
+
5. CLick "Generate release notes"
|
180
|
+
6. Click "Publish release"
|
181
|
+
|
148
182
|
## Thanks
|
149
183
|
|
150
184
|
[Andrew J Vargo](http://github.com/ajvargo) Andrew was the original creator and maintainer of this project!
|
data/lib/data_migrate/config.rb
CHANGED
@@ -12,12 +12,22 @@ module DataMigrate
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class Config
|
15
|
-
attr_accessor :data_migrations_path, :db_configuration, :spec_name
|
15
|
+
attr_accessor :data_migrations_table_name, :data_migrations_path, :data_template_path, :db_configuration, :spec_name
|
16
|
+
|
17
|
+
DEFAULT_DATA_TEMPLATE_PATH = "data_migration.rb"
|
16
18
|
|
17
19
|
def initialize
|
20
|
+
@data_migrations_table_name = "data_migrations"
|
18
21
|
@data_migrations_path = "db/data/"
|
22
|
+
@data_template_path = DEFAULT_DATA_TEMPLATE_PATH
|
19
23
|
@db_configuration = nil
|
20
24
|
@spec_name = nil
|
21
25
|
end
|
26
|
+
|
27
|
+
def data_template_path=(value)
|
28
|
+
@data_template_path = value.tap do |path|
|
29
|
+
raise ArgumentError, "File not found: '#{path}'" unless path == DEFAULT_DATA_TEMPLATE_PATH || File.exist?(path)
|
30
|
+
end
|
31
|
+
end
|
22
32
|
end
|
23
33
|
end
|
@@ -5,33 +5,20 @@ require "data_migrate/config"
|
|
5
5
|
|
6
6
|
module DataMigrate
|
7
7
|
class DataMigrator < ActiveRecord::Migrator
|
8
|
-
def self.migrations_paths
|
9
|
-
[DataMigrate.config.data_migrations_path]
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.assure_data_schema_table
|
13
|
-
ActiveRecord::Base.establish_connection(db_config)
|
14
|
-
DataMigrate::DataSchemaMigration.create_table
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize(direction, migrations, target_version = nil)
|
18
|
-
@direction = direction
|
19
|
-
@target_version = target_version
|
20
|
-
@migrated_versions = nil
|
21
|
-
@migrations = migrations
|
22
|
-
|
23
|
-
validate(@migrations)
|
24
|
-
|
25
|
-
DataMigrate::DataSchemaMigration.create_table
|
26
|
-
ActiveRecord::InternalMetadata.create_table
|
27
|
-
end
|
28
|
-
|
29
8
|
def load_migrated
|
30
9
|
@migrated_versions =
|
31
|
-
DataMigrate::
|
10
|
+
DataMigrate::RailsHelper.data_schema_migration.normalized_versions.map(&:to_i).sort
|
32
11
|
end
|
33
12
|
|
34
13
|
class << self
|
14
|
+
def migrations_paths
|
15
|
+
Array.wrap(DataMigrate.config.data_migrations_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_data_schema_table
|
19
|
+
DataMigrate::RailsHelper.data_schema_migration.create_table
|
20
|
+
end
|
21
|
+
|
35
22
|
def current_version
|
36
23
|
DataMigrate::MigrationContext.new(migrations_paths).current_version
|
37
24
|
end
|
@@ -61,28 +48,21 @@ module DataMigrate
|
|
61
48
|
|
62
49
|
# TODO: this was added to be backward compatible, need to re-evaluate
|
63
50
|
def migrations(_migrations_paths)
|
64
|
-
#DataMigrate::MigrationContext.new(migrations_paths).migrations
|
65
51
|
DataMigrate::MigrationContext.new(_migrations_paths).migrations
|
66
52
|
end
|
67
53
|
|
68
54
|
#TODO: this was added to be backward compatible, need to re-evaluate
|
69
55
|
def run(direction, migration_paths, version)
|
56
|
+
# Ensure all Active Record model cache is reset for each data migration
|
57
|
+
# As recommended in: https://github.com/rails/rails/blob/da21c2e9812e5eb0698fba4a9aa38632fc004432/activerecord/lib/active_record/migration.rb#L467-L470
|
58
|
+
ActiveRecord::Base.descendants.each(&:reset_column_information)
|
59
|
+
|
70
60
|
DataMigrate::MigrationContext.new(migration_paths).run(direction, version)
|
71
61
|
end
|
72
62
|
|
73
63
|
def rollback(migrations_path, steps)
|
74
64
|
DataMigrate::MigrationContext.new(migrations_path).rollback(steps)
|
75
65
|
end
|
76
|
-
|
77
|
-
def db_config
|
78
|
-
env = Rails.env || "development"
|
79
|
-
ar_config = if (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 6
|
80
|
-
ActiveRecord::Base.configurations.configs_for(env_name: env).first
|
81
|
-
else
|
82
|
-
ActiveRecord::Base.configurations[env]
|
83
|
-
end
|
84
|
-
ar_config || ENV["DATABASE_URL"]
|
85
|
-
end
|
86
66
|
end
|
87
67
|
|
88
68
|
private
|
@@ -90,10 +70,10 @@ module DataMigrate
|
|
90
70
|
def record_version_state_after_migrating(version)
|
91
71
|
if down?
|
92
72
|
migrated.delete(version)
|
93
|
-
DataMigrate::
|
73
|
+
DataMigrate::RailsHelper.data_schema_delete_version(version.to_s)
|
94
74
|
else
|
95
75
|
migrated << version
|
96
|
-
DataMigrate::
|
76
|
+
DataMigrate::RailsHelper.data_schema_migration.create_version(version.to_s)
|
97
77
|
end
|
98
78
|
end
|
99
79
|
end
|
@@ -9,7 +9,7 @@ module DataMigrate
|
|
9
9
|
# ActiveRecord::ConnectionAdapters::SchemaStatements
|
10
10
|
# #assume_migrated_upto_version
|
11
11
|
def define(info)
|
12
|
-
DataMigrate::DataMigrator.
|
12
|
+
DataMigrate::DataMigrator.create_data_schema_table
|
13
13
|
|
14
14
|
return if info[:version].blank?
|
15
15
|
|
@@ -29,13 +29,13 @@ module DataMigrate
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def versions
|
32
|
-
@versions ||=
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
@versions ||= Set.new.tap do |versions|
|
33
|
+
DataMigrate::DataMigrator.migrations_paths.each do |path|
|
34
|
+
Dir.foreach(path) do |file|
|
35
|
+
match_data = DataMigrate::DataMigrator.match(file)
|
36
|
+
versions << match_data[1].to_i if match_data
|
37
|
+
end
|
37
38
|
end
|
38
|
-
versions
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -57,7 +57,7 @@ module DataMigrate
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def table_name
|
60
|
-
DataMigrate::
|
60
|
+
DataMigrate::RailsHelper.data_schema_migration.table_name
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -1,15 +1,31 @@
|
|
1
1
|
module DataMigrate
|
2
|
-
class DataSchemaMigration <
|
3
|
-
|
4
|
-
|
2
|
+
class DataSchemaMigration < ActiveRecord::SchemaMigration
|
3
|
+
# In Rails 7.1+, ActiveRecord::SchemaMigration methods are instance methods
|
4
|
+
# So we only load the appropriate methods depending on Rails version.
|
5
|
+
if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_1
|
5
6
|
def table_name
|
6
|
-
ActiveRecord::Base.table_name_prefix +
|
7
|
+
ActiveRecord::Base.table_name_prefix + DataMigrate.config.data_migrations_table_name + ActiveRecord::Base.table_name_suffix
|
7
8
|
end
|
8
9
|
|
9
10
|
def primary_key
|
10
11
|
"version"
|
11
12
|
end
|
13
|
+
else
|
14
|
+
class << self
|
15
|
+
def table_name
|
16
|
+
ActiveRecord::Base.table_name_prefix + DataMigrate.config.data_migrations_table_name + ActiveRecord::Base.table_name_suffix
|
17
|
+
end
|
18
|
+
|
19
|
+
def primary_key
|
20
|
+
"version"
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_version(version)
|
24
|
+
# Note that SchemaMigration.create_version in Rails 7.1 does not
|
25
|
+
# raise an error if validations fail but we retain this behaviour for now.
|
26
|
+
create!(version: version)
|
27
|
+
end
|
28
|
+
end
|
12
29
|
end
|
13
30
|
end
|
14
31
|
end
|
15
|
-
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module DataMigrate
|
2
|
+
# This wrapper is used to differentiate between
|
3
|
+
# a data and schema db config when running migrations
|
4
|
+
class DatabaseConfigurationWrapper
|
5
|
+
attr_reader :db_config
|
6
|
+
|
7
|
+
def initialize(db_config)
|
8
|
+
@db_config = db_config
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|