Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Changelog

# 11.2.0
# Unreleased
- Use lease_connection over deprecated connection for rails 8 https://github.com/ilyakatz/data-migrate/pull/353

# 11.2.0
- Remove committed Gemfile.lock, reduce bundled file list when running `gem install` https://github.com/ilyakatz/data-migrate/pull/351
- [Bump actionpack from 7.1.3.4 to 7.1.4.1](https://github.com/ilyakatz/data-migrate/pull/348)
- [Bump rexml from 3.3.6 to 3.3.9](https://github.com/ilyakatz/data-migrate/pull/349)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ From now on capistrano will run `rake db:migrate:with_data` in every deploy.
## Rails Engines support

This gem also has a initial support for adding data migrations inside Rails engines.
Just add your engines directory pattern to data_migrations initializer, for example
Just add your engines directory pattern to data_migrations initializer, for example
in the case your engines are located in `engines` folder you can set it up like this:

```ruby
Expand All @@ -166,6 +166,7 @@ bundle exec appraisal rails-6.1 rspec
bundle exec appraisal rails-7.0 rspec
bundle exec appraisal rails-7.1 rspec
bundle exec appraisal rails-7.2 rspec
bundle exec appraisal rails-8.0 rspec
```

## Releasing new version
Expand Down
1 change: 0 additions & 1 deletion lib/data_migrate/data_migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def migrations_status

# TODO: this was added to be backward compatible, need to re-evaluate
def migrations(_migrations_paths)
#DataMigrate::MigrationContext.new(migrations_paths).migrations
DataMigrate::MigrationContext.new(_migrations_paths).migrations
end

Expand Down
14 changes: 11 additions & 3 deletions lib/data_migrate/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ module DatabaseTasks
extend ActiveRecord::Tasks::DatabaseTasks
extend self

if respond_to?(:register_task)
register_task(/mysql/, "ActiveRecord::Tasks::MySQLDatabaseTasks")
register_task(/trilogy/, "ActiveRecord::Tasks::MySQLDatabaseTasks")
register_task(/postgresql/, "ActiveRecord::Tasks::PostgreSQLDatabaseTasks")
register_task(/sqlite/, "ActiveRecord::Tasks::SQLiteDatabaseTasks")
end

# These method are only introduced in Rails 7.1
unless respond_to?(:with_temporary_pool_for_each)
def with_temporary_pool_for_each(env: ActiveRecord::Tasks::DatabaseTasks.env, name: nil, &block) # :nodoc:
Expand Down Expand Up @@ -99,7 +106,7 @@ def pending_migrations
end

def sort_migrations(*migrations)
migrations.flatten.sort { |a, b| sort_string(a) <=> sort_string(b) }
migrations.flatten.sort { |a, b| sort_string(a) <=> sort_string(b) }
end

def sort_string migration
Expand Down Expand Up @@ -159,7 +166,7 @@ def pending_data_migrations
data_migrator = DataMigrate::RailsHelper.data_migrator(:up, data_migrations)
sort_migrations(
data_migrator.pending_migrations.map { |m| { version: m.version, name: m.name, kind: :data } }
)
)
end

def pending_schema_migrations
Expand Down Expand Up @@ -219,7 +226,8 @@ def self.prepare_all_with_data
next unless primary?(db_config)

with_temporary_pool(db_config) do |pool|
unless database_exists?(pool.connection)
connection = pool.respond_to?(:lease_connection) ? pool.lease_connection : pool.connection
unless database_exists?(connection)
create(db_config)
if File.exist?(schema_dump_path(db_config))
load_schema(db_config, schema_format, nil)
Expand Down
2 changes: 1 addition & 1 deletion spec/data_migrate/database_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
before do
allow(subject).to receive(:each_current_configuration).and_yield(db_config)
allow(subject).to receive(:with_temporary_pool).with(db_config).and_yield(pool)
allow(pool).to receive(:connection).and_return(connection)
allow(pool).to receive(:lease_connection).and_return(connection)
allow(subject).to receive(:schema_dump_path).and_return("db/data_schema.rb")
allow(File).to receive(:exist?).and_return(true)
allow(subject).to receive(:load_schema)
Expand Down
Loading