data_migrate 9.4.2 → 10.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +3 -3
- data/.github/workflows/gempush.yml +8 -6
- data/.gitignore +2 -3
- data/.ruby-version +1 -0
- data/.travis.yml +14 -0
- data/Appraisals +5 -5
- data/Changelog.md +2 -46
- data/Gemfile +1 -0
- data/Gemfile.rails6.1 +11 -0
- data/README.md +5 -7
- data/data_migrate.gemspec +2 -2
- data/gemfiles/{rails_7.1.gemfile → rails_6.0.gemfile} +2 -1
- data/gemfiles/rails_6.1.gemfile +1 -0
- data/gemfiles/rails_7.0.gemfile +2 -1
- data/lib/data_migrate/data_migrator.rb +23 -15
- data/lib/data_migrate/data_schema.rb +2 -2
- data/lib/data_migrate/data_schema_migration.rb +7 -24
- data/lib/data_migrate/database_tasks.rb +48 -194
- data/lib/data_migrate/legacy_migrator.rb +22 -0
- data/lib/data_migrate/migration_context.rb +8 -11
- data/lib/data_migrate/schema_dumper.rb +1 -1
- data/lib/data_migrate/schema_migration.rb +4 -5
- data/lib/data_migrate/status_service.rb +4 -4
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +15 -14
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +1 -2
- data/spec/data_migrate/data_migrator_spec.rb +14 -17
- data/spec/data_migrate/data_schema_migration_spec.rb +8 -25
- data/spec/data_migrate/data_spec.rb +1 -1
- data/spec/data_migrate/database_tasks_spec.rb +19 -34
- data/spec/data_migrate/legacy_migrator_spec.rb +38 -0
- data/spec/data_migrate/migration_context_spec.rb +8 -15
- data/spec/data_migrate/schema_dumper_spec.rb +3 -6
- data/spec/data_migrate/schema_migration_spec.rb +6 -13
- data/spec/data_migrate/status_service_spec.rb +4 -7
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +14 -13
- data/spec/db/data/20091231235959_some_name.rb +1 -1
- data/spec/db/data/20171231235959_super_update.rb +1 -1
- data/spec/db/migrate/20131111111111_late_migration.rb +1 -1
- data/spec/db/migrate/20202020202011_db_migration.rb +1 -1
- data/tasks/databases.rake +83 -25
- metadata +19 -21
- data/Gemfile.lock +0 -184
- data/gemfiles/rails_6.1.gemfile.lock +0 -229
- data/gemfiles/rails_7.0.gemfile.lock +0 -230
- data/gemfiles/rails_7.1.gemfile.lock +0 -263
- data/lib/data_migrate/database_configurations_wrapper.rb +0 -11
- data/lib/data_migrate/rails_helper.rb +0 -79
- data/lib/data_migrate/test.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d212f0e6fa0c9b767cbdf17854c7c52d640a9c8611d0b10ed6c0460de68985cd
|
4
|
+
data.tar.gz: ac338ef447f1942d64eb5cf6c0fe520f71089968c04fb03fb829a1318534b4eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01ae940433e4cd51a2f421297fb3ffb72372503971ee906164129c035c89aedb6c18d5003cd083930c24245f16728c38c93aed94fb8d9b2f7d0288895362a3d4
|
7
|
+
data.tar.gz: 9d94ff40ed274256247960c0dd1325645b638ac2198d29b3bce2c3c11f842b4b0a2b381bd73fcb17af308ab366cdca16c7f99c9e2fa778da7ab6103352e50ba1
|
data/.github/workflows/build.yml
CHANGED
@@ -11,14 +11,14 @@ jobs:
|
|
11
11
|
matrix:
|
12
12
|
os: [ "ubuntu-20.04" ]
|
13
13
|
ruby:
|
14
|
+
- '2.7'
|
14
15
|
- '3.0'
|
15
16
|
- '3.1'
|
16
17
|
- '3.2'
|
17
|
-
- '3.3'
|
18
18
|
gemfile:
|
19
|
+
- gemfiles/rails_6.0.gemfile
|
19
20
|
- gemfiles/rails_6.1.gemfile
|
20
21
|
- gemfiles/rails_7.0.gemfile
|
21
|
-
- gemfiles/rails_7.1.gemfile
|
22
22
|
runs-on: ubuntu-latest
|
23
23
|
env:
|
24
24
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
@@ -32,4 +32,4 @@ jobs:
|
|
32
32
|
ruby-version: ${{ matrix.ruby }}
|
33
33
|
bundler-cache: true
|
34
34
|
- name: Run tests
|
35
|
-
run: bundle exec rspec
|
35
|
+
run: bundle exec rspec
|
@@ -1,8 +1,10 @@
|
|
1
|
-
name:
|
1
|
+
name: Ruby Gem
|
2
2
|
|
3
3
|
on:
|
4
|
-
|
5
|
-
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
- chaunce-multiple_connection_support
|
6
8
|
|
7
9
|
jobs:
|
8
10
|
build:
|
@@ -11,10 +13,10 @@ jobs:
|
|
11
13
|
|
12
14
|
steps:
|
13
15
|
- uses: actions/checkout@master
|
14
|
-
- name: Set up Ruby
|
15
|
-
uses:
|
16
|
+
- name: Set up Ruby 2.6
|
17
|
+
uses: actions/setup-ruby@v1
|
16
18
|
with:
|
17
|
-
|
19
|
+
version: 2.6.x
|
18
20
|
|
19
21
|
- name: Publish to RubyGems
|
20
22
|
run: |
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.5
|
data/.travis.yml
ADDED
data/Appraisals
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
+
appraise 'rails-6.0' do
|
2
|
+
gem 'rails', '~> 6.0.0'
|
3
|
+
end
|
4
|
+
|
1
5
|
appraise 'rails-6.1' do
|
2
6
|
gem 'rails', '~> 6.1.0'
|
3
7
|
end
|
4
8
|
|
5
9
|
appraise 'rails-7.0' do
|
6
|
-
gem 'rails', '~> 7.0
|
7
|
-
end
|
8
|
-
|
9
|
-
appraise 'rails-7.1' do
|
10
|
-
gem 'rails', '7.1.0'
|
10
|
+
gem 'rails', '~> 7.0'
|
11
11
|
end
|
data/Changelog.md
CHANGED
@@ -1,57 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
4
|
-
- Fix db:prepare:with_data task
|
5
|
-
|
6
|
-
## 9.4.1
|
7
|
-
- Add db:prepare task
|
8
|
-
|
9
|
-
## 9.4.0
|
10
|
-
- Reset model schema cache before each data migration https://github.com/ilyakatz/data-migrate/pull/307
|
11
|
-
- Run load_config rake task before db:migrate:with_data https://github.com/ilyakatz/data-migrate/pull/308
|
12
|
-
|
13
|
-
## 9.3.0
|
14
|
-
- Improve with_data Rake task for multiple database https://github.com/ilyakatz/data-migrate/pull/296
|
15
|
-
|
16
|
-
## 9.2.0
|
17
|
-
- Support Rails 7.1 https://github.com/ilyakatz/data-migrate/pull/278
|
18
|
-
- Build and test against 7.1.0.rc1 https://github.com/ilyakatz/data-migrate/pull/286
|
19
|
-
|
20
|
-
## 9.1.0
|
21
|
-
|
22
|
-
- Fix a bug that caused `schema_sha1` in `ar_internal_metadata` to be reset to the `data_schema.rb` file. (#272)
|
23
|
-
- Remove the need for empty data_schema files for non-primary databases. (#273)
|
24
|
-
|
25
|
-
## [YANKED] 10.0.3.rc
|
26
|
-
|
27
|
-
- Remove all travis references [leoarnold](https//:github.com/leoarnold)
|
28
|
-
- Changing to rc because of ongoing discussion how to properly handle multiple database environments
|
29
|
-
|
30
|
-
## [YANKED] 10.0.2
|
31
|
-
|
32
|
-
Change "rails" dependencies to "railties"
|
33
|
-
|
34
|
-
## [YANKED] 10.0.1
|
35
|
-
|
36
|
-
- Bug fix for Rails 6 config [chaunce](https//:github.com/chaunce)
|
37
|
-
- Railties bug fix by [opti](https://github.com/opti)
|
38
|
-
|
39
|
-
## [YANKED] 10.0.0
|
40
|
-
|
41
|
-
Releasing 10.0.0
|
42
|
-
|
43
|
-
!!! Breaking changes !!!
|
44
|
-
|
45
|
-
- This version introduces a breaking change which may lead to undesired
|
46
|
-
behavior in multi-database environments. See https://github.com/ilyakatz/data-migrate/issues/181
|
47
|
-
|
48
|
-
## [YANKED] 10.0.0.rc1
|
3
|
+
## 10.0.0.rc1
|
49
4
|
|
50
5
|
- Changes by [chaunce](https//:github.com/chaunce)
|
51
6
|
- Multiple databases support
|
52
7
|
- Refactor to clean things up
|
53
8
|
- Deprecate rails 5.2 support for real
|
54
9
|
|
10
|
+
|
55
11
|
## 9.0.0
|
56
12
|
|
57
13
|
Ruby 3.2 support [mehanoid](https://github.com/mehanoid)
|
data/Gemfile
CHANGED
data/Gemfile.rails6.1
ADDED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
- [![Version](http://img.shields.io/gem/v/data_migrate.svg?style=flat-square)](https://rubygems.org/gems/data_migrate)
|
4
4
|
- [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
|
5
|
-
- ![.
|
5
|
+
- [![Travis](https://img.shields.io/travis/ilyakatz/data-migrate.svg)](https://travis-ci.org/ilyakatz/data-migrate)
|
6
6
|
- [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](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
|
-
![
|
15
|
+
![Travis](./screenshot.png)
|
16
16
|
|
17
17
|
## Why should I use this?
|
18
18
|
|
@@ -36,7 +36,7 @@ table to track all migrations.
|
|
36
36
|
|
37
37
|
## Rails Support
|
38
38
|
|
39
|
-
Support Rails 6.
|
39
|
+
Support Rails 6.0 through 7.0
|
40
40
|
|
41
41
|
|
42
42
|
#### v1
|
@@ -96,9 +96,7 @@ Tasks work as they would with the 'vanilla' db version. The 'with_data' addition
|
|
96
96
|
|
97
97
|
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
98
|
|
99
|
-
|
100
|
-
|
101
|
-
`rake db:migrate:status:with_data` provides an additional column to indicate which type of migration.
|
99
|
+
`rake db:migrate:status:with_data` provides and additional column to indicate which type of migration.
|
102
100
|
|
103
101
|
### Configuration
|
104
102
|
|
@@ -164,9 +162,9 @@ Run tests for a specific version of Rails
|
|
164
162
|
|
165
163
|
```
|
166
164
|
bundle exec appraisal install
|
165
|
+
bundle exec appraisal rails-6.0 rspec
|
167
166
|
bundle exec appraisal rails-6.1 rspec
|
168
167
|
bundle exec appraisal rails-7.0 rspec
|
169
|
-
bundle exec appraisal rails-7.1 rspec
|
170
168
|
```
|
171
169
|
|
172
170
|
## Thanks
|
data/data_migrate.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
activerecord
|
20
20
|
railties
|
21
21
|
].each do |rails_gem|
|
22
|
-
s.add_dependency(rails_gem, '>= 6.
|
22
|
+
s.add_dependency(rails_gem, '>= 6.0')
|
23
23
|
end
|
24
24
|
|
25
25
|
s.add_development_dependency "appraisal"
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_development_dependency "rspec-core"
|
29
29
|
s.add_development_dependency "pry"
|
30
30
|
s.add_development_dependency "rb-readline"
|
31
|
-
s.add_development_dependency "sqlite3"
|
31
|
+
s.add_development_dependency "sqlite3", "~> 1.3.6"
|
32
32
|
s.add_development_dependency "timecop"
|
33
33
|
s.add_development_dependency "rubocop"
|
34
34
|
s.add_development_dependency "overcommit"
|
data/gemfiles/rails_6.1.gemfile
CHANGED
data/gemfiles/rails_7.0.gemfile
CHANGED
@@ -5,20 +5,32 @@ 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
|
+
DataMigrate::DataSchemaMigration.create_table
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(direction, migrations, target_version = nil)
|
17
|
+
@direction = direction
|
18
|
+
@target_version = target_version
|
19
|
+
@migrated_versions = nil
|
20
|
+
@migrations = migrations
|
21
|
+
|
22
|
+
validate(@migrations)
|
23
|
+
|
24
|
+
DataMigrate::DataSchemaMigration.create_table
|
25
|
+
ActiveRecord::InternalMetadata.create_table
|
26
|
+
end
|
27
|
+
|
8
28
|
def load_migrated
|
9
29
|
@migrated_versions =
|
10
|
-
DataMigrate::
|
30
|
+
DataMigrate::DataSchemaMigration.normalized_versions.map(&:to_i).sort
|
11
31
|
end
|
12
32
|
|
13
33
|
class << self
|
14
|
-
def migrations_paths
|
15
|
-
[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
|
-
|
22
34
|
def current_version
|
23
35
|
DataMigrate::MigrationContext.new(migrations_paths).current_version
|
24
36
|
end
|
@@ -54,10 +66,6 @@ module DataMigrate
|
|
54
66
|
|
55
67
|
#TODO: this was added to be backward compatible, need to re-evaluate
|
56
68
|
def run(direction, migration_paths, version)
|
57
|
-
# Ensure all Active Record model cache is reset for each data migration
|
58
|
-
# As recommended in: https://github.com/rails/rails/blob/da21c2e9812e5eb0698fba4a9aa38632fc004432/activerecord/lib/active_record/migration.rb#L467-L470
|
59
|
-
ActiveRecord::Base.descendants.each(&:reset_column_information)
|
60
|
-
|
61
69
|
DataMigrate::MigrationContext.new(migration_paths).run(direction, version)
|
62
70
|
end
|
63
71
|
|
@@ -71,10 +79,10 @@ module DataMigrate
|
|
71
79
|
def record_version_state_after_migrating(version)
|
72
80
|
if down?
|
73
81
|
migrated.delete(version)
|
74
|
-
DataMigrate::
|
82
|
+
DataMigrate::DataSchemaMigration.where(version: version.to_s).delete_all
|
75
83
|
else
|
76
84
|
migrated << version
|
77
|
-
DataMigrate::
|
85
|
+
DataMigrate::DataSchemaMigration.create!(version: version.to_s)
|
78
86
|
end
|
79
87
|
end
|
80
88
|
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.assure_data_schema_table
|
13
13
|
|
14
14
|
return if info[:version].blank?
|
15
15
|
|
@@ -57,7 +57,7 @@ module DataMigrate
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def table_name
|
60
|
-
DataMigrate::
|
60
|
+
DataMigrate::DataSchemaMigration.table_name
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -1,29 +1,12 @@
|
|
1
1
|
module DataMigrate
|
2
|
-
class DataSchemaMigration
|
3
|
-
|
4
|
-
|
5
|
-
if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_1
|
6
|
-
def table_name
|
7
|
-
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
|
8
|
-
end
|
9
|
-
|
10
|
-
def primary_key
|
11
|
-
"version"
|
12
|
-
end
|
13
|
-
else
|
14
|
-
class << self
|
15
|
-
def table_name
|
16
|
-
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
|
17
|
-
end
|
18
|
-
|
19
|
-
def primary_key
|
20
|
-
"version"
|
21
|
-
end
|
2
|
+
class DataSchemaMigration
|
3
|
+
class << self
|
4
|
+
delegate :table_name, :primary_key, :create_table, :normalized_versions, :create, :create!, :table_exists?, :exists?, :where, to: :instance
|
22
5
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
6
|
+
def instance
|
7
|
+
@instance ||= Class.new(::ActiveRecord::SchemaMigration) do
|
8
|
+
define_singleton_method(:table_name) { ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix }
|
9
|
+
define_singleton_method(:primary_key) { "version" }
|
27
10
|
end
|
28
11
|
end
|
29
12
|
end
|