Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db:prepare:with_data): add missing prepare_all_with_data and task definition #321

Merged
merged 1 commit into from
Aug 14, 2024
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
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 9.4.2
- Fix db:prepare:with_data task

## 9.4.1
- Add db:prepare task

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
data_migrate (9.4.1)
data_migrate (9.4.2)
activerecord (>= 6.1)
railties (>= 6.1)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6.1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
data_migrate (9.4.1)
data_migrate (9.4.2)
activerecord (>= 6.1)
railties (>= 6.1)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
data_migrate (9.4.1)
data_migrate (9.4.2)
activerecord (>= 6.1)
railties (>= 6.1)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
data_migrate (9.4.1)
data_migrate (9.4.2)
activerecord (>= 6.1)
railties (>= 6.1)

Expand Down
37 changes: 37 additions & 0 deletions lib/data_migrate/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,42 @@ def self.migrate_with_data
end
end
end

def self.prepare_all_with_data
seed = false

each_current_configuration(env) do |db_config|
next unless db_config.primary?

with_temporary_pool(db_config) do
begin
database_initialized = migration_connection.schema_migration.table_exists?
rescue ActiveRecord::NoDatabaseError
create(db_config)
retry
end

unless database_initialized
if File.exist?(schema_dump_path(db_config))
load_schema(db_config, ActiveRecord.schema_format, nil)
load_schema_current(
:ruby,
ENV["DATA_SCHEMA"]
)
end

seed = true
end

migrate_with_data
if ActiveRecord.dump_schema_after_migration
dump_schema(db_config)
DataMigrate::Tasks::DataMigrateTasks.dump
end
end
end

load_seed if seed
end
end
end
2 changes: 1 addition & 1 deletion lib/data_migrate/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DataMigrate
VERSION = "9.4.1".freeze
VERSION = "9.4.2".freeze
end
7 changes: 7 additions & 0 deletions tasks/databases.rake
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ namespace :db do
end
end
end

namespace :prepare do
desc "Runs setup if database does not exist, or runs data and schema migrations if it does"
task with_data: :environment do
DataMigrate::DatabaseTasks.prepare_all_with_data
end
end
end

namespace :data do
Expand Down
Loading