data_migrate 9.2.0 → 10.0.0.rc1
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/.github/workflows/build.yml +3 -2
- 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 -33
- data/README.md +5 -7
- data/data_migrate.gemspec +1 -1
- data/gemfiles/{rails_7.1.gemfile → rails_6.0.gemfile} +1 -1
- data/gemfiles/rails_6.1.gemfile +1 -1
- data/lib/data_migrate/data_migrator.rb +23 -11
- 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 +5 -28
- 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 -1
- 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 +38 -17
- metadata +14 -15
- data/Gemfile.lock +0 -148
- data/gemfiles/rails_6.1.gemfile.lock +0 -227
- data/gemfiles/rails_7.0.gemfile.lock +0 -229
- data/gemfiles/rails_7.1.gemfile.lock +0 -262
- data/lib/data_migrate/rails_helper.rb +0 -79
    
        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,13 +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 18 | 
             
                    gemfile:
         | 
| 19 | 
            +
                      - gemfiles/rails_6.0.gemfile
         | 
| 18 20 | 
             
                      - gemfiles/rails_6.1.gemfile
         | 
| 19 21 | 
             
                      - gemfiles/rails_7.0.gemfile
         | 
| 20 | 
            -
                      - gemfiles/rails_7.1.gemfile
         | 
| 21 22 | 
             
                runs-on: ubuntu-latest
         | 
| 22 23 | 
             
                env:
         | 
| 23 24 | 
             
                  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
         | 
| @@ -31,4 +32,4 @@ jobs: | |
| 31 32 | 
             
                      ruby-version: ${{ matrix.ruby }}
         | 
| 32 33 | 
             
                      bundler-cache: true
         | 
| 33 34 | 
             
                  - name: Run tests
         | 
| 34 | 
            -
                    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,44 +1,13 @@ | |
| 1 1 | 
             
            # Changelog
         | 
| 2 2 |  | 
| 3 | 
            -
            ##  | 
| 4 | 
            -
            - Support Rails 7.1 https://github.com/ilyakatz/data-migrate/pull/278
         | 
| 5 | 
            -
            - Build and test against 7.1.0.rc1 https://github.com/ilyakatz/data-migrate/pull/286
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            ## 9.1.0
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            - Fix a bug that caused `schema_sha1` in `ar_internal_metadata` to be reset to the `data_schema.rb` file. (#272)
         | 
| 10 | 
            -
            - Remove the need for empty data_schema files for non-primary databases. (#273)
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            ## [YANKED] 10.0.3.rc
         | 
| 13 | 
            -
             | 
| 14 | 
            -
            - Remove all travis references [leoarnold](https//:github.com/leoarnold)
         | 
| 15 | 
            -
            - Changing to rc because of ongoing discussion how to properly handle multiple database environments
         | 
| 16 | 
            -
             | 
| 17 | 
            -
            ## [YANKED] 10.0.2
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            Change "rails" dependencies to "railties"
         | 
| 20 | 
            -
             | 
| 21 | 
            -
            ## [YANKED] 10.0.1
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            - Bug fix for Rails 6 config [chaunce](https//:github.com/chaunce)
         | 
| 24 | 
            -
            - Railties bug fix by [opti](https://github.com/opti)
         | 
| 25 | 
            -
             | 
| 26 | 
            -
            ## [YANKED] 10.0.0
         | 
| 27 | 
            -
             | 
| 28 | 
            -
            Releasing 10.0.0
         | 
| 29 | 
            -
             | 
| 30 | 
            -
            !!! Breaking changes !!!
         | 
| 31 | 
            -
             | 
| 32 | 
            -
            - This version introduces a breaking change which may lead to undesired
         | 
| 33 | 
            -
            behavior in multi-database environments. See https://github.com/ilyakatz/data-migrate/issues/181
         | 
| 34 | 
            -
             | 
| 35 | 
            -
            ## [YANKED] 10.0.0.rc1
         | 
| 3 | 
            +
            ## 10.0.0.rc1
         | 
| 36 4 |  | 
| 37 5 | 
             
            - Changes by [chaunce](https//:github.com/chaunce)
         | 
| 38 6 | 
             
            - Multiple databases support
         | 
| 39 7 | 
             
            - Refactor to clean things up
         | 
| 40 8 | 
             
            - Deprecate rails 5.2 support for real
         | 
| 41 9 |  | 
| 10 | 
            +
             | 
| 42 11 | 
             
            ## 9.0.0
         | 
| 43 12 |  | 
| 44 13 | 
             
            Ruby 3.2 support [mehanoid](https://github.com/mehanoid)
         | 
    
        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 | 
            -
            - ](https://travis-ci.org/ilyakatz/data-migrate)
         | 
| 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,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
    
    
    
        data/gemfiles/rails_6.1.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
         | 
| @@ -67,10 +79,10 @@ module DataMigrate | |
| 67 79 | 
             
                def record_version_state_after_migrating(version)
         | 
| 68 80 | 
             
                  if down?
         | 
| 69 81 | 
             
                    migrated.delete(version)
         | 
| 70 | 
            -
                    DataMigrate:: | 
| 82 | 
            +
                    DataMigrate::DataSchemaMigration.where(version: version.to_s).delete_all
         | 
| 71 83 | 
             
                  else
         | 
| 72 84 | 
             
                    migrated << version
         | 
| 73 | 
            -
                    DataMigrate:: | 
| 85 | 
            +
                    DataMigrate::DataSchemaMigration.create!(version: version.to_s)
         | 
| 74 86 | 
             
                  end
         | 
| 75 87 | 
             
                end
         | 
| 76 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
         | 
| @@ -9,15 +9,10 @@ module DataMigrate | |
| 9 9 | 
             
                extend ActiveRecord::Tasks::DatabaseTasks
         | 
| 10 10 |  | 
| 11 11 | 
             
                class << self
         | 
| 12 | 
            -
                  def schema_file(_format = nil)
         | 
| 13 | 
            -
                    File.join(db_dir, "data_schema.rb")
         | 
| 14 | 
            -
                  end
         | 
| 15 | 
            -
             | 
| 16 12 | 
             
                  def schema_file_type(_format = nil)
         | 
| 17 13 | 
             
                    "data_schema.rb"
         | 
| 18 14 | 
             
                  end
         | 
| 19 15 |  | 
| 20 | 
            -
                  # This method is removed in Rails 7.0
         | 
| 21 16 | 
             
                  def dump_filename(spec_name, format = ActiveRecord::Base.schema_format)
         | 
| 22 17 | 
             
                    filename = if spec_name == "primary"
         | 
| 23 18 | 
             
                      schema_file_type(format)
         | 
| @@ -67,26 +62,10 @@ module DataMigrate | |
| 67 62 | 
             
                      )
         | 
| 68 63 | 
             
                    end
         | 
| 69 64 | 
             
                  end
         | 
| 70 | 
            -
             | 
| 71 | 
            -
                  def schema_dump_path(db_config, format = ActiveRecord.schema_format)
         | 
| 72 | 
            -
                    return ENV["DATA_SCHEMA"] if ENV["DATA_SCHEMA"]
         | 
| 73 | 
            -
             | 
| 74 | 
            -
                    # We only require a schema.rb file for the primary database
         | 
| 75 | 
            -
                    return unless db_config.primary?
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                    File.join(File.dirname(ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(db_config, format)), schema_file_type)
         | 
| 78 | 
            -
                  end
         | 
| 79 | 
            -
             | 
| 80 | 
            -
                  # Override this method from `ActiveRecord::Tasks::DatabaseTasks`
         | 
| 81 | 
            -
                  # to ensure that the sha saved in ar_internal_metadata table
         | 
| 82 | 
            -
                  # is from the original schema.rb file
         | 
| 83 | 
            -
                  def schema_sha1(file)
         | 
| 84 | 
            -
                    ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env, name: "primary"))
         | 
| 85 | 
            -
                  end
         | 
| 86 65 | 
             
                end
         | 
| 87 66 |  | 
| 88 67 | 
             
                def self.forward(step = 1)
         | 
| 89 | 
            -
                  DataMigrate::DataMigrator. | 
| 68 | 
            +
                  DataMigrate::DataMigrator.assure_data_schema_table
         | 
| 90 69 | 
             
                  migrations = pending_migrations.reverse.pop(step).reverse
         | 
| 91 70 | 
             
                  migrations.each do | pending_migration |
         | 
| 92 71 | 
             
                    if pending_migration[:kind] == :data
         | 
| @@ -101,10 +80,8 @@ module DataMigrate | |
| 101 80 |  | 
| 102 81 | 
             
                def self.pending_data_migrations
         | 
| 103 82 | 
             
                  data_migrations = DataMigrate::DataMigrator.migrations(data_migrations_path)
         | 
| 104 | 
            -
                   | 
| 105 | 
            -
             | 
| 106 | 
            -
                    data_migrator.pending_migrations.map { |m| { version: m.version, name: m.name, kind: :data } }
         | 
| 107 | 
            -
                    )
         | 
| 83 | 
            +
                  sort_migrations(DataMigrate::DataMigrator.new(:up, data_migrations ).
         | 
| 84 | 
            +
                    pending_migrations.map {|m| { version: m.version, name: m.name, kind: :data }})
         | 
| 108 85 | 
             
                end
         | 
| 109 86 |  | 
| 110 87 | 
             
                def self.pending_schema_migrations
         | 
| @@ -112,8 +89,8 @@ module DataMigrate | |
| 112 89 | 
             
                end
         | 
| 113 90 |  | 
| 114 91 | 
             
                def self.past_migrations(sort = nil)
         | 
| 115 | 
            -
                  data_versions = DataMigrate:: | 
| 116 | 
            -
                  schema_versions =  | 
| 92 | 
            +
                  data_versions = DataMigrate::DataSchemaMigration.table_exists? ? DataMigrate::DataSchemaMigration.normalized_versions : []
         | 
| 93 | 
            +
                  schema_versions = ActiveRecord::SchemaMigration.normalized_versions
         | 
| 117 94 | 
             
                  migrations = data_versions.map { |v| { version: v.to_i, kind: :data } } + schema_versions.map { |v| { version: v.to_i, kind: :schema } }
         | 
| 118 95 |  | 
| 119 96 | 
             
                  sort&.downcase == "asc" ? sort_migrations(migrations) : sort_migrations(migrations).reverse
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            module DataMigrate
         | 
| 2 | 
            +
              class LegacyMigrator
         | 
| 3 | 
            +
                def initialize(migrations_paths = "db/data")
         | 
| 4 | 
            +
                  @migrations_paths = migrations_paths || "db/data"
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def migrate
         | 
| 8 | 
            +
                  dates =
         | 
| 9 | 
            +
                    DataMigrate::DataMigrator.migrations(@migrations_paths).collect(&:version)
         | 
| 10 | 
            +
                  legacy = ActiveRecord::SchemaMigration.where(version: dates)
         | 
| 11 | 
            +
                  legacy.each do |v|
         | 
| 12 | 
            +
                    begin
         | 
| 13 | 
            +
                      version = v.version
         | 
| 14 | 
            +
                      puts "Creating #{version} in data schema"
         | 
| 15 | 
            +
                      DataMigrate::DataSchemaMigration.create(version: version)
         | 
| 16 | 
            +
                    rescue ActiveRecord::RecordNotUnique
         | 
| 17 | 
            +
                      nil
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
| @@ -11,8 +11,7 @@ module DataMigrate | |
| 11 11 | 
             
                                          migrations
         | 
| 12 12 | 
             
                                        end
         | 
| 13 13 |  | 
| 14 | 
            -
                   | 
| 15 | 
            -
                  data_migrator.migrate
         | 
| 14 | 
            +
                  DataMigrator.new(:up, selected_migrations, target_version).migrate
         | 
| 16 15 | 
             
                end
         | 
| 17 16 |  | 
| 18 17 | 
             
                def down(target_version = nil)
         | 
| @@ -23,13 +22,11 @@ module DataMigrate | |
| 23 22 | 
             
                      migrations
         | 
| 24 23 | 
             
                    end
         | 
| 25 24 |  | 
| 26 | 
            -
                   | 
| 27 | 
            -
                  data_migrator.migrate
         | 
| 25 | 
            +
                  DataMigrator.new(:down, selected_migrations, target_version).migrate
         | 
| 28 26 | 
             
                end
         | 
| 29 27 |  | 
| 30 28 | 
             
                def run(direction, target_version)
         | 
| 31 | 
            -
                   | 
| 32 | 
            -
                  data_migrator.run
         | 
| 29 | 
            +
                  DataMigrator.new(direction, migrations, target_version).run
         | 
| 33 30 | 
             
                end
         | 
| 34 31 |  | 
| 35 32 | 
             
                def current_version
         | 
| @@ -43,12 +40,12 @@ module DataMigrate | |
| 43 40 | 
             
                end
         | 
| 44 41 |  | 
| 45 42 | 
             
                def migrations_status
         | 
| 46 | 
            -
                  db_list =  | 
| 43 | 
            +
                  db_list = DataSchemaMigration.normalized_versions
         | 
| 47 44 |  | 
| 48 45 | 
             
                  file_list = migration_files.map do |file|
         | 
| 49 46 | 
             
                    version, name, scope = parse_migration_filename(file)
         | 
| 50 47 | 
             
                    raise ActiveRecord::IllegalMigrationNameError.new(file) unless version
         | 
| 51 | 
            -
                    version =  | 
| 48 | 
            +
                    version = ActiveRecord::SchemaMigration.normalize_migration_number(version)
         | 
| 52 49 | 
             
                    status = db_list.delete(version) ? "up" : "down"
         | 
| 53 50 | 
             
                    [status, version, (name + scope).humanize]
         | 
| 54 51 | 
             
                  end.compact
         | 
| @@ -63,15 +60,15 @@ module DataMigrate | |
| 63 60 | 
             
                private
         | 
| 64 61 |  | 
| 65 62 | 
             
                def get_all_versions
         | 
| 66 | 
            -
                  if DataMigrate:: | 
| 67 | 
            -
                     | 
| 63 | 
            +
                  if DataMigrate::DataSchemaMigration.table_exists?
         | 
| 64 | 
            +
                    DataSchemaMigration.normalized_versions.map(&:to_i)
         | 
| 68 65 | 
             
                  else
         | 
| 69 66 | 
             
                    []
         | 
| 70 67 | 
             
                  end
         | 
| 71 68 | 
             
                end
         | 
| 72 69 |  | 
| 73 70 | 
             
                def move(direction, steps)
         | 
| 74 | 
            -
                  migrator =  | 
| 71 | 
            +
                  migrator = DataMigrator.new(direction, migrations)
         | 
| 75 72 |  | 
| 76 73 | 
             
                  if current_version != 0 && !migrator.current_migration
         | 
| 77 74 | 
             
                    raise ActiveRecord::UnknownMigrationVersionError.new(current_version)
         | 
| @@ -26,7 +26,7 @@ module DataMigrate | |
| 26 26 |  | 
| 27 27 | 
             
                def initialize(connection)
         | 
| 28 28 | 
             
                  @connection = connection
         | 
| 29 | 
            -
                  all_versions =   | 
| 29 | 
            +
                  all_versions =  DataSchemaMigration.normalized_versions
         | 
| 30 30 |  | 
| 31 31 | 
             
                  @version = begin
         | 
| 32 32 | 
             
                                all_versions.max
         | 
| @@ -7,14 +7,14 @@ module DataMigrate | |
| 7 7 | 
             
                def self.pending_schema_migrations
         | 
| 8 8 | 
             
                  all_migrations = DataMigrate::MigrationContext.new(migrations_paths).migrations
         | 
| 9 9 | 
             
                  sort_migrations(
         | 
| 10 | 
            -
                    ActiveRecord::Migrator.new(:up, all_migrations,  | 
| 10 | 
            +
                    ActiveRecord::Migrator.new(:up, all_migrations, ActiveRecord::Base.connection.schema_migration).
         | 
| 11 11 | 
             
                    pending_migrations.
         | 
| 12 12 | 
             
                    map {|m| { version: m.version, kind: :schema }}
         | 
| 13 13 | 
             
                  )
         | 
| 14 14 | 
             
                end
         | 
| 15 15 |  | 
| 16 16 | 
             
                def self.run(direction, migration_paths, version)
         | 
| 17 | 
            -
                  ActiveRecord::MigrationContext.new(migration_paths,  | 
| 17 | 
            +
                  ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::Base.connection.schema_migration).run(direction, version)
         | 
| 18 18 | 
             
                end
         | 
| 19 19 |  | 
| 20 20 | 
             
                def self.sort_migrations(set1, set2 = nil)
         | 
| @@ -24,10 +24,9 @@ module DataMigrate | |
| 24 24 |  | 
| 25 25 | 
             
                def self.migrations_paths
         | 
| 26 26 | 
             
                  spec_name = DataMigrate.config.spec_name
         | 
| 27 | 
            -
                   | 
| 28 | 
            -
                  if spec_name && Gem::Dependency.new("railties", ">= 7.0").match?("railties", Gem.loaded_specs["railties"].version, true)
         | 
| 27 | 
            +
                  if spec_name && Gem::Dependency.new("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
         | 
| 29 28 | 
             
                    ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: spec_name).migrations_paths
         | 
| 30 | 
            -
                  elsif spec_name && Gem::Dependency.new(" | 
| 29 | 
            +
                  elsif spec_name && Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
         | 
| 31 30 | 
             
                    ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: spec_name).migrations_paths
         | 
| 32 31 | 
             
                  else
         | 
| 33 32 | 
             
                    Rails.application.config.paths["db/migrate"].to_a
         | 
| @@ -24,11 +24,11 @@ module DataMigrate | |
| 24 24 | 
             
                private
         | 
| 25 25 |  | 
| 26 26 | 
             
                def table_name
         | 
| 27 | 
            -
                  DataMigrate:: | 
| 27 | 
            +
                  DataMigrate::DataSchemaMigration.table_name
         | 
| 28 28 | 
             
                end
         | 
| 29 29 |  | 
| 30 30 | 
             
                def output(stream)
         | 
| 31 | 
            -
                  unless DataMigrate:: | 
| 31 | 
            +
                  unless DataMigrate::DataSchemaMigration.table_exists?
         | 
| 32 32 | 
             
                    stream.puts "Data migrations table does not exist yet."
         | 
| 33 33 | 
             
                    return
         | 
| 34 34 | 
             
                  end
         | 
| @@ -44,9 +44,9 @@ module DataMigrate | |
| 44 44 | 
             
                end
         | 
| 45 45 |  | 
| 46 46 | 
             
                def database_name
         | 
| 47 | 
            -
                  if Gem::Dependency.new(" | 
| 47 | 
            +
                  if Gem::Dependency.new("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
         | 
| 48 48 | 
             
                    ActiveRecord::Base.connection_db_config.configuration_hash[:database]
         | 
| 49 | 
            -
                  elsif Gem::Dependency.new(" | 
| 49 | 
            +
                  elsif Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
         | 
| 50 50 | 
             
                    ActiveRecord::Base.connection_config[:database]
         | 
| 51 51 | 
             
                  end
         | 
| 52 52 | 
             
                end
         | 
| @@ -9,9 +9,9 @@ module DataMigrate | |
| 9 9 | 
             
                    @migrations_paths ||= DataMigrate.config.data_migrations_path
         | 
| 10 10 | 
             
                  end
         | 
| 11 11 |  | 
| 12 | 
            -
                  def dump
         | 
| 12 | 
            +
                  def dump(db_config)
         | 
| 13 13 | 
             
                    if dump_schema_after_migration?
         | 
| 14 | 
            -
                      filename = DataMigrate::DatabaseTasks. | 
| 14 | 
            +
                      filename = DataMigrate::DatabaseTasks.dump_filename(spec_name(db_config), ActiveRecord::Base.schema_format)
         | 
| 15 15 | 
             
                      ActiveRecord::Base.establish_connection(DataMigrate.config.db_configuration) if DataMigrate.config.db_configuration
         | 
| 16 16 | 
             
                      File.open(filename, "w:utf-8") do |file|
         | 
| 17 17 | 
             
                        DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, file)
         | 
| @@ -22,7 +22,7 @@ module DataMigrate | |
| 22 22 | 
             
                  def migrate
         | 
| 23 23 | 
             
                    target_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
         | 
| 24 24 |  | 
| 25 | 
            -
                    DataMigrate::DataMigrator. | 
| 25 | 
            +
                    DataMigrate::DataMigrator.assure_data_schema_table
         | 
| 26 26 | 
             
                    DataMigrate::MigrationContext.new(migrations_paths).migrate(target_version)
         | 
| 27 27 | 
             
                  end
         | 
| 28 28 |  | 
| @@ -44,15 +44,16 @@ module DataMigrate | |
| 44 44 | 
             
                    end
         | 
| 45 45 | 
             
                  end
         | 
| 46 46 |  | 
| 47 | 
            -
                  def status
         | 
| 48 | 
            -
                     | 
| 47 | 
            +
                  def status(db_config)
         | 
| 48 | 
            +
                    puts "\ndatabase: #{spec_name(db_config)}\n\n"
         | 
| 49 | 
            +
                    DataMigrate::StatusService.dump(ActiveRecord::Base.connection)
         | 
| 49 50 | 
             
                  end
         | 
| 50 51 |  | 
| 51 | 
            -
                  def status_with_schema
         | 
| 52 | 
            +
                  def status_with_schema(db_config)
         | 
| 52 53 | 
             
                    db_list_data = ActiveRecord::Base.connection.select_values(
         | 
| 53 | 
            -
                      "SELECT version FROM #{DataMigrate:: | 
| 54 | 
            +
                      "SELECT version FROM #{DataMigrate::DataSchemaMigration.table_name}"
         | 
| 54 55 | 
             
                    )
         | 
| 55 | 
            -
                    db_list_schema =  | 
| 56 | 
            +
                    db_list_schema = ActiveRecord::SchemaMigration.all.pluck(:version)
         | 
| 56 57 | 
             
                    file_list = []
         | 
| 57 58 |  | 
| 58 59 | 
             
                    Dir.foreach(File.join(Rails.root, migrations_paths)) do |file|
         | 
| @@ -76,7 +77,7 @@ module DataMigrate | |
| 76 77 | 
             
                    file_list.sort!{|a,b| "#{a[1]}_#{a[3] == 'data' ? 1 : 0}" <=> "#{b[1]}_#{b[3] == 'data' ? 1 : 0}" }
         | 
| 77 78 |  | 
| 78 79 | 
             
                    # output
         | 
| 79 | 
            -
                    puts "\ndatabase: #{ | 
| 80 | 
            +
                    puts "\ndatabase: #{spec_name(db_config)}\n\n"
         | 
| 80 81 | 
             
                    puts "#{"Status".center(8)} #{"Type".center(8)}  #{"Migration ID".ljust(14)} Migration Name"
         | 
| 81 82 | 
             
                    puts "-" * 60
         | 
| 82 83 | 
             
                    file_list.each do |file|
         | 
| @@ -93,11 +94,11 @@ module DataMigrate | |
| 93 94 |  | 
| 94 95 | 
             
                  private
         | 
| 95 96 |  | 
| 96 | 
            -
                  def  | 
| 97 | 
            -
                    if Gem::Dependency.new(" | 
| 98 | 
            -
                       | 
| 99 | 
            -
                    elsif Gem::Dependency.new(" | 
| 100 | 
            -
                       | 
| 97 | 
            +
                  def spec_name(db_config)
         | 
| 98 | 
            +
                    if Gem::Dependency.new("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
         | 
| 99 | 
            +
                      db_config.name
         | 
| 100 | 
            +
                    elsif Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
         | 
| 101 | 
            +
                      db_config.spec_name
         | 
| 101 102 | 
             
                    end
         | 
| 102 103 | 
             
                  end
         | 
| 103 104 | 
             
                end
         | 
    
        data/lib/data_migrate/version.rb
    CHANGED