Skip to content

Commit

Permalink
Get schema migrations from one place (#179)
Browse files Browse the repository at this point in the history
* Use normal way to get schema migrations

* whitespace

* Bump version

* Update changelog
  • Loading branch information
lewhit authored May 12, 2021
1 parent 6890921 commit 8a99cea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
4 changes: 3 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Changelog
## 7.0.1
Use SchemaMigrations.migration_paths in main rake task [lewhit](https://github.com/lewhit)

## 6.8.0

Specify database name for migrations_paths [lewhit](https://github.com/lewhit)
# 6.7.0
## 6.7.0

Add configuration for which database name is to be used for database migrations [lewhit](https://github.com/lewhit)
Add tests for Rails 6.1 [lewhit](https://github.com/lewhit)
Expand Down
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 = "7.0.0".freeze
VERSION = "7.0.1".freeze
end
50 changes: 18 additions & 32 deletions tasks/databases.rake
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,7 @@ namespace :db do
end

migrations.each do |migration|
if migration[:kind] == :data
ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
DataMigrate::DataMigrator.run(migration[:direction], data_migrations_path, migration[:version])
else
ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
DataMigrate::SchemaMigration.run(
migration[:direction],
Rails.application.config.paths["db/migrate"],
migration[:version]
)
end
run_migration(migration, migration[:direction])
end

Rake::Task["db:_dump"].invoke
Expand Down Expand Up @@ -91,13 +81,7 @@ namespace :db do
end

migrations.each do |migration|
if migration[:kind] == :data
ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
DataMigrate::DataMigrator.run(:up, data_migrations_path, migration[:version])
else
ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
DataMigrate::SchemaMigration.run(:up, "db/migrate/", migration[:version])
end
run_migration(migration, :up)
end

Rake::Task["db:_dump"].invoke
Expand All @@ -119,13 +103,7 @@ namespace :db do
end

migrations.each do |migration|
if migration[:kind] == :data
ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
DataMigrate::DataMigrator.run(:down, data_migrations_path, migration[:version])
else
ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
DataMigrate::SchemaMigration.run(:down, "db/migrate/", migration[:version])
end
run_migration(migration, :down)
end

Rake::Task["db:_dump"].invoke
Expand Down Expand Up @@ -189,13 +167,7 @@ namespace :db do
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
assure_data_schema_table
past_migrations[0..(step - 1)].each do | past_migration |
if past_migration[:kind] == :data
ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
DataMigrate::DataMigrator.run(:down, data_migrations_path, past_migration[:version])
elsif past_migration[:kind] == :schema
ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
DataMigrate::SchemaMigration.run(:down, "db/migrate/", past_migration[:version])
end
run_migration(past_migration, :down)
end

Rake::Task["db:_dump"].invoke
Expand Down Expand Up @@ -412,3 +384,17 @@ end
def data_migrations_path
DataMigrate.config.data_migrations_path
end

def run_migration(migration, direction)
if migration[:kind] == :data
ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
DataMigrate::DataMigrator.run(direction, data_migrations_path, migration[:version])
else
ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
DataMigrate::SchemaMigration.run(
direction,
DataMigrate::SchemaMigration.migrations_paths,
migration[:version]
)
end
end

0 comments on commit 8a99cea

Please sign in to comment.