data_migrate 9.1.1 → 10.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e439cb5180eca3cf1195560f8942178ac4ca64304489f1ec3ce3b1efa3462be4
4
- data.tar.gz: efe9f8166f6fd7080d68b6dc050ac63124528d66ccc0465a505cd1002bbd7dce
3
+ metadata.gz: d212f0e6fa0c9b767cbdf17854c7c52d640a9c8611d0b10ed6c0460de68985cd
4
+ data.tar.gz: ac338ef447f1942d64eb5cf6c0fe520f71089968c04fb03fb829a1318534b4eb
5
5
  SHA512:
6
- metadata.gz: 64ca4079825785ca93b6e636a62b9117d15e5b6e10c667467657b229833014286e3339c644360f5ffa1ddab83bafca3dbff0397e5b1ecaa75eb646fe87b637d0
7
- data.tar.gz: c9dced4b2efe056e2519ad8493c2d25a165d122f6350569a191b182d8d6f6e189f40fbff744f1b31039810636cd603b18363618080b4eb502570e1943828631d
6
+ metadata.gz: 01ae940433e4cd51a2f421297fb3ffb72372503971ee906164129c035c89aedb6c18d5003cd083930c24245f16728c38c93aed94fb8d9b2f7d0288895362a3d4
7
+ data.tar.gz: 9d94ff40ed274256247960c0dd1325645b638ac2198d29b3bce2c3c11f842b4b0a2b381bd73fcb17af308ab366cdca16c7f99c9e2fa778da7ab6103352e50ba1
@@ -11,6 +11,7 @@ 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'
@@ -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: Release Gem
1
+ name: Ruby Gem
2
2
 
3
3
  on:
4
- release:
5
- types: [released]
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 3.2
15
- uses: ruby/setup-ruby@v1
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
16
18
  with:
17
- ruby-version: '3.2'
19
+ version: 2.6.x
18
20
 
19
21
  - name: Publish to RubyGems
20
22
  run: |
data/.gitignore CHANGED
@@ -7,7 +7,5 @@ spec/db/other_test.db
7
7
  spec/db/data_schema.rb
8
8
  .vscode/
9
9
  .DS_Store
10
- .ruby-gemset
11
- .ruby-version
12
10
  .idea/
13
- vendor/
11
+ vendor/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.5
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.7
4
+ - 3.0
5
+ - 3.2
6
+ script: bundle exec rspec
7
+ gemfile:
8
+ - gemfiles/rails_6.0.gemfile
9
+ - gemfiles/rails_6.1.gemfile
10
+ - gemfiles/rails_7.0.gemfile
11
+ jobs:
12
+ exclude:
13
+ - rvm: 3.0
14
+ - rvm: 3.2
data/Changelog.md CHANGED
@@ -1,40 +1,13 @@
1
1
  # Changelog
2
2
 
3
- ## 9.1.0
4
-
5
- - Fix a bug that caused `schema_sha1` in `ar_internal_metadata` to be reset to the `data_schema.rb` file. (#272)
6
- - Remove the need for empty data_schema files for non-primary databases. (#273)
7
-
8
- ## [YANKED] 10.0.3.rc
9
-
10
- - Remove all travis references [leoarnold](https//:github.com/leoarnold)
11
- - Changing to rc because of ongoing discussion how to properly handle multiple database environments
12
-
13
- ## [YANKED] 10.0.2
14
-
15
- Change "rails" dependencies to "railties"
16
-
17
- ## [YANKED] 10.0.1
18
-
19
- - Bug fix for Rails 6 config [chaunce](https//:github.com/chaunce)
20
- - Railties bug fix by [opti](https://github.com/opti)
21
-
22
- ## [YANKED] 10.0.0
23
-
24
- Releasing 10.0.0
25
-
26
- !!! Breaking changes !!!
27
-
28
- - This version introduces a breaking change which may lead to undesired
29
- behavior in multi-database environments. See https://github.com/ilyakatz/data-migrate/issues/181
30
-
31
- ## [YANKED] 10.0.0.rc1
3
+ ## 10.0.0.rc1
32
4
 
33
5
  - Changes by [chaunce](https//:github.com/chaunce)
34
6
  - Multiple databases support
35
7
  - Refactor to clean things up
36
8
  - Deprecate rails 5.2 support for real
37
9
 
10
+
38
11
  ## 9.0.0
39
12
 
40
13
  Ruby 3.2 support [mehanoid](https://github.com/mehanoid)
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
- - ![.github/workflows/build.yml](https://github.com/ilyakatz/data-migrate/actions/workflows/.github/workflows/build.yml/badge.svg)
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
- ![directory tree example](./screenshot.png)
15
+ ![Travis](./screenshot.png)
16
16
 
17
17
  ## Why should I use this?
18
18
 
@@ -92,13 +92,11 @@ You can generate a data migration as you would a schema migration:
92
92
  rake db:version:with_data # Retrieves the current schema version numbers for data and schema migrations
93
93
 
94
94
 
95
- 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.
95
+ 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.
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
- 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.
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
 
@@ -9,7 +9,7 @@ module DataMigrate
9
9
  [DataMigrate.config.data_migrations_path]
10
10
  end
11
11
 
12
- def self.create_data_schema_table
12
+ def self.assure_data_schema_table
13
13
  DataMigrate::DataSchemaMigration.create_table
14
14
  end
15
15
 
@@ -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.create_data_schema_table
12
+ DataMigrate::DataMigrator.assure_data_schema_table
13
13
 
14
14
  return if info[:version].blank?
15
15
 
@@ -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.create_data_schema_table
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
@@ -24,9 +24,9 @@ module DataMigrate
24
24
 
25
25
  def self.migrations_paths
26
26
  spec_name = DataMigrate.config.spec_name
27
- if spec_name && Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
27
+ if spec_name && Gem::Dependency.new("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
28
28
  ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: spec_name).migrations_paths
29
- elsif spec_name && Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
29
+ elsif spec_name && Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
30
30
  ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: spec_name).migrations_paths
31
31
  else
32
32
  Rails.application.config.paths["db/migrate"].to_a
@@ -44,9 +44,9 @@ module DataMigrate
44
44
  end
45
45
 
46
46
  def database_name
47
- if Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
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("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
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.schema_file
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.create_data_schema_table
25
+ DataMigrate::DataMigrator.assure_data_schema_table
26
26
  DataMigrate::MigrationContext.new(migrations_paths).migrate(target_version)
27
27
  end
28
28
 
@@ -44,11 +44,12 @@ module DataMigrate
44
44
  end
45
45
  end
46
46
 
47
- def status
48
- DataMigrate::StatusService.dump
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
54
  "SELECT version FROM #{DataMigrate::DataSchemaMigration.table_name}"
54
55
  )
@@ -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: #{database_name}\n\n"
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 database_name
97
- if Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
98
- ActiveRecord::Base.connection_db_config.database
99
- elsif Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
100
- ActiveRecord::Base.connection_config[:database]
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
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "9.1.1".freeze
2
+ VERSION = "10.0.0.rc1".freeze
3
3
  end
@@ -35,10 +35,10 @@ describe DataMigrate::DataMigrator do
35
35
  end
36
36
  end
37
37
 
38
- describe :create_data_schema_table do
38
+ describe :assure_data_schema_table do
39
39
  it "creates the data_migrations table" do
40
40
  ActiveRecord::Migration.drop_table("data_migrations") rescue nil
41
- subject.create_data_schema_table
41
+ subject.assure_data_schema_table
42
42
  expect(
43
43
  ActiveRecord::Base.connection.table_exists?("data_migrations")
44
44
  ).to eq true
@@ -28,7 +28,7 @@ describe DataMigrate::DatabaseTasks do
28
28
  data_migrations_path
29
29
  }
30
30
  ActiveRecord::Base.establish_connection(db_config)
31
- if Gem::Dependency.new("railties", ">= 6.1").match?("railties", Gem.loaded_specs["railties"].version)
31
+ if Gem::Dependency.new("rails", ">= 6.1").match?("rails", Gem.loaded_specs["rails"].version)
32
32
  hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', db_config)
33
33
  config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
34
34
  allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
@@ -69,6 +69,7 @@ describe DataMigrate::DatabaseTasks do
69
69
  end
70
70
 
71
71
  describe :forward do
72
+
72
73
  it "run forward default amount of times" do
73
74
  subject.forward
74
75
  versions = DataMigrate::DataSchemaMigration.normalized_versions
@@ -61,9 +61,9 @@ describe DataMigrate::SchemaMigration do
61
61
  let(:paths) { ['spec/db/migrate', 'spec/db/migrate/other'] }
62
62
  let(:specification_name) { "primary" }
63
63
  let(:config_options) do
64
- if Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
64
+ if Gem::Dependency.new("rails", "~> 6.0").match?("rails", Gem.loaded_specs["rails"].version)
65
65
  { env_name: Rails.env, spec_name: specification_name }
66
- elsif Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
66
+ elsif Gem::Dependency.new("rails", "~> 7.0").match?("rails", Gem.loaded_specs["rails"].version)
67
67
  { env_name: Rails.env, name: specification_name }
68
68
  end
69
69
  end
@@ -7,7 +7,7 @@ describe DataMigrate::StatusService do
7
7
  let(:stream) { StringIO.new }
8
8
  let(:stream_data) { stream.read }
9
9
  let(:connection_db_config) do
10
- if Gem::Dependency.new("railties", ">= 6.1").match?("railties", Gem.loaded_specs["railties"].version)
10
+ if Gem::Dependency.new("rails", ">= 6.1").match?("rails", Gem.loaded_specs["rails"].version)
11
11
  ActiveRecord::Base.connection_db_config
12
12
  else
13
13
  ActiveRecord::Base.configurations.configs_for.first
@@ -4,7 +4,7 @@ require "spec_helper"
4
4
 
5
5
  describe DataMigrate::Tasks::DataMigrateTasks do
6
6
  let(:connection_db_config) do
7
- if Gem::Dependency.new("railties", ">= 6.1").match?("railties", Gem.loaded_specs["railties"].version)
7
+ if Gem::Dependency.new("rails", ">= 6.1").match?("rails", Gem.loaded_specs["rails"].version)
8
8
  ActiveRecord::Base.connection_db_config
9
9
  else
10
10
  ActiveRecord::Base.configurations.configs_for.first
@@ -28,11 +28,11 @@ describe DataMigrate::Tasks::DataMigrateTasks do
28
28
  end
29
29
 
30
30
  context 'when not given a separate db config' do
31
- it 'does not override the default connection' do
31
+ it 'does not override the default connection' do
32
32
  expect(ActiveRecord::Base).not_to receive(:establish_connection)
33
33
  expect(DataMigrate::SchemaDumper).to receive(:dump)
34
34
 
35
- DataMigrate::Tasks::DataMigrateTasks.dump
35
+ DataMigrate::Tasks::DataMigrateTasks.dump(connection_db_config)
36
36
  end
37
37
  end
38
38
 
@@ -56,7 +56,8 @@ describe DataMigrate::Tasks::DataMigrateTasks do
56
56
 
57
57
  it 'overrides the default connection' do
58
58
  expect(ActiveRecord::Base).to receive(:establish_connection).with(override_config)
59
- DataMigrate::Tasks::DataMigrateTasks.dump
59
+
60
+ DataMigrate::Tasks::DataMigrateTasks.dump(connection_db_config)
60
61
  end
61
62
  end
62
63
  end
@@ -115,13 +116,13 @@ describe DataMigrate::Tasks::DataMigrateTasks do
115
116
 
116
117
  it "should display data migration status" do
117
118
  expect {
118
- DataMigrate::Tasks::DataMigrateTasks.status
119
+ DataMigrate::Tasks::DataMigrateTasks.status(connection_db_config)
119
120
  }.to output(/up 20091231235959 Some name/).to_stdout
120
121
  end
121
122
 
122
123
  it "should display schema and data migration status" do
123
124
  expect {
124
- DataMigrate::Tasks::DataMigrateTasks.status_with_schema
125
+ DataMigrate::Tasks::DataMigrateTasks.status_with_schema(connection_db_config)
125
126
  }.to output(match(/up data 20091231235959 Some name/)
126
127
  .and match(/down schema 20131111111111 Late migration/)).to_stdout
127
128
  end
data/tasks/databases.rake CHANGED
@@ -6,7 +6,10 @@ namespace :db do
6
6
  namespace :migrate do
7
7
  desc "Migrate the database data and schema (options: VERSION=x, VERBOSE=false)."
8
8
  task :with_data => :environment do
9
- DataMigrate::DataMigrator.create_data_schema_table
9
+ original_db_config = ActiveRecord::Base.connection_db_config
10
+ ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
11
+ ActiveRecord::Base.establish_connection(db_config)
12
+ DataMigrate::DataMigrator.assure_data_schema_table
10
13
 
11
14
  ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
12
15
  target_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
@@ -50,15 +53,18 @@ namespace :db do
50
53
  migrations.each do |migration|
51
54
  DataMigrate::DatabaseTasks.run_migration(migration, migration[:direction])
52
55
  end
56
+ end
53
57
 
54
58
  Rake::Task["db:_dump"].invoke
55
59
  Rake::Task["data:dump"].invoke
60
+ ensure
61
+ ActiveRecord::Base.establish_connection(original_db_config)
56
62
  end
57
63
 
58
64
  namespace :redo do
59
65
  desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
60
66
  task :with_data => :environment do
61
- DataMigrate::DataMigrator.create_data_schema_table
67
+ DataMigrate::DataMigrator.assure_data_schema_table
62
68
  if ENV["VERSION"]
63
69
  Rake::Task["db:migrate:down:with_data"].invoke
64
70
  Rake::Task["db:migrate:up:with_data"].invoke
@@ -74,7 +80,7 @@ namespace :db do
74
80
  task :with_data => :environment do
75
81
  version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
76
82
  raise "VERSION is required" unless version
77
- DataMigrate::DataMigrator.create_data_schema_table
83
+ DataMigrate::DataMigrator.assure_data_schema_table
78
84
  run_both = ENV["BOTH"] == "true"
79
85
  migrations = DataMigrate::DatabaseTasks.pending_migrations.keep_if{|m| m[:version] == version}
80
86
 
@@ -96,7 +102,7 @@ namespace :db do
96
102
  task :with_data => :environment do
97
103
  version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
98
104
  raise "VERSION is required" unless version
99
- DataMigrate::DataMigrator.create_data_schema_table
105
+ DataMigrate::DataMigrator.assure_data_schema_table
100
106
  run_both = ENV["BOTH"] == "true"
101
107
  migrations = DataMigrate::DatabaseTasks.past_migrations.keep_if{|m| m[:version] == version}
102
108
 
@@ -116,7 +122,10 @@ namespace :db do
116
122
  namespace :status do
117
123
  desc "Display status of data and schema migrations"
118
124
  task :with_data => :environment do
119
- DataMigrate::Tasks::DataMigrateTasks.status_with_schema
125
+ ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
126
+ ActiveRecord::Base.establish_connection(db_config)
127
+ DataMigrate::Tasks::DataMigrateTasks.status_with_schema(db_config)
128
+ end
120
129
  end
121
130
  end
122
131
  end # END OF MIGRATE NAME SPACE
@@ -125,7 +134,7 @@ namespace :db do
125
134
  desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
126
135
  task :with_data => :environment do
127
136
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
128
- DataMigrate::DataMigrator.create_data_schema_table
137
+ DataMigrate::DataMigrator.assure_data_schema_table
129
138
  DataMigrate::DatabaseTasks.past_migrations[0..(step - 1)].each do | past_migration |
130
139
  DataMigrate::DatabaseTasks.run_migration(past_migration, :down)
131
140
  end
@@ -138,7 +147,7 @@ namespace :db do
138
147
  namespace :forward do
139
148
  desc 'Pushes the schema to the next version (specify steps w/ STEP=n).'
140
149
  task :with_data => :environment do
141
- DataMigrate::DataMigrator.create_data_schema_table
150
+ DataMigrate::DataMigrator.assure_data_schema_table
142
151
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
143
152
  DataMigrate::DatabaseTasks.forward(step)
144
153
  Rake::Task["db:_dump"].invoke
@@ -149,7 +158,7 @@ namespace :db do
149
158
  namespace :version do
150
159
  desc "Retrieves the current schema version numbers for data and schema migrations"
151
160
  task :with_data => :environment do
152
- DataMigrate::DataMigrator.create_data_schema_table
161
+ DataMigrate::DataMigrator.assure_data_schema_table
153
162
  puts "Current Schema version: #{ActiveRecord::Migrator.current_version}"
154
163
  puts "Current Data version: #{DataMigrate::DataMigrator.current_version}"
155
164
  end
@@ -195,14 +204,20 @@ end
195
204
  namespace :data do
196
205
  desc 'Migrate data migrations (options: VERSION=x, VERBOSE=false)'
197
206
  task :migrate => :environment do
198
- DataMigrate::Tasks::DataMigrateTasks.migrate
207
+ original_db_config = ActiveRecord::Base.connection_db_config
208
+ ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
209
+ ActiveRecord::Base.establish_connection(db_config)
210
+ DataMigrate::Tasks::DataMigrateTasks.migrate
211
+ end
199
212
  Rake::Task["data:dump"].invoke
213
+ ensure
214
+ ActiveRecord::Base.establish_connection(original_db_config)
200
215
  end
201
216
 
202
217
  namespace :migrate do
203
218
  desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
204
219
  task :redo => :environment do
205
- DataMigrate::DataMigrator.create_data_schema_table
220
+ DataMigrate::DataMigrator.assure_data_schema_table
206
221
  if ENV["VERSION"]
207
222
  Rake::Task["data:migrate:down"].invoke
208
223
  Rake::Task["data:migrate:up"].invoke
@@ -214,7 +229,7 @@ namespace :data do
214
229
 
215
230
  desc 'Runs the "up" for a given migration VERSION.'
216
231
  task :up => :environment do
217
- DataMigrate::DataMigrator.create_data_schema_table
232
+ DataMigrate::DataMigrator.assure_data_schema_table
218
233
  version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
219
234
  raise "VERSION is required" unless version
220
235
  DataMigrate::DataMigrator.run(:up, DataMigrate::DatabaseTasks.data_migrations_path, version)
@@ -225,20 +240,23 @@ namespace :data do
225
240
  task :down => :environment do
226
241
  version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
227
242
  raise "VERSION is required" unless version
228
- DataMigrate::DataMigrator.create_data_schema_table
243
+ DataMigrate::DataMigrator.assure_data_schema_table
229
244
  DataMigrate::DataMigrator.run(:down, DataMigrate::DatabaseTasks.data_migrations_path, version)
230
245
  Rake::Task["data:dump"].invoke
231
246
  end
232
247
 
233
248
  desc "Display status of data migrations"
234
249
  task :status => :environment do
235
- DataMigrate::Tasks::DataMigrateTasks.status
250
+ ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
251
+ ActiveRecord::Base.establish_connection(db_config)
252
+ DataMigrate::Tasks::DataMigrateTasks.status(db_config)
253
+ end
236
254
  end
237
255
  end
238
256
 
239
257
  desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
240
258
  task :rollback => :environment do
241
- DataMigrate::DataMigrator.create_data_schema_table
259
+ DataMigrate::DataMigrator.assure_data_schema_table
242
260
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
243
261
  DataMigrate::DataMigrator.rollback(DataMigrate::DatabaseTasks.data_migrations_path, step)
244
262
  Rake::Task["data:dump"].invoke
@@ -246,7 +264,7 @@ namespace :data do
246
264
 
247
265
  desc 'Pushes the schema to the next version (specify steps w/ STEP=n).'
248
266
  task :forward => :environment do
249
- DataMigrate::DataMigrator.create_data_schema_table
267
+ DataMigrate::DataMigrator.assure_data_schema_table
250
268
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
251
269
  # TODO: No worky for .forward
252
270
  # DataMigrate::DataMigrator.forward('db/data/', step)
@@ -259,7 +277,7 @@ namespace :data do
259
277
 
260
278
  desc "Retrieves the current schema version number for data migrations"
261
279
  task :version => :environment do
262
- DataMigrate::DataMigrator.create_data_schema_table
280
+ DataMigrate::DataMigrator.assure_data_schema_table
263
281
  puts "Current data version: #{DataMigrate::DataMigrator.current_version}"
264
282
  end
265
283
 
@@ -271,7 +289,10 @@ namespace :data do
271
289
 
272
290
  desc "Create a db/data_schema.rb file that stores the current data version"
273
291
  task dump: :environment do
274
- DataMigrate::Tasks::DataMigrateTasks.dump
292
+ ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
293
+ ActiveRecord::Base.establish_connection(db_config)
294
+ DataMigrate::Tasks::DataMigrateTasks.dump(db_config)
295
+ end
275
296
 
276
297
  # Allow this task to be called as many times as required. An example
277
298
  # is the migrate:redo task, which calls other two internally
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.1
4
+ version: 10.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew J Vargo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-08-02 00:00:00.000000000 Z
13
+ date: 2023-04-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -198,6 +198,8 @@ files:
198
198
  - ".rspec"
199
199
  - ".rubocop.yml"
200
200
  - ".ruby-style.yml"
201
+ - ".ruby-version"
202
+ - ".travis.yml"
201
203
  - Appraisals
202
204
  - Changelog.md
203
205
  - Gemfile
@@ -270,11 +272,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
270
272
  version: '0'
271
273
  required_rubygems_version: !ruby/object:Gem::Requirement
272
274
  requirements:
273
- - - ">="
275
+ - - ">"
274
276
  - !ruby/object:Gem::Version
275
- version: '0'
277
+ version: 1.3.1
276
278
  requirements: []
277
- rubygems_version: 3.4.10
279
+ rubygems_version: 3.3.26
278
280
  signing_key:
279
281
  specification_version: 4
280
282
  summary: Rake tasks to migrate data alongside schema changes.