Last active
April 29, 2019 08:58
-
-
Save roalcantara/a53083a313ecf2ba9aa65596da4cee13 to your computer and use it in GitHub Desktop.
[Rails 5] Overriding `db:schema:load` rake in order to load legacy schema before running the default `db:schema:load` task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lib/tasks/remove_task.rake | |
Rake::TaskManager.class_eval do | |
def remove_task(task_name) | |
@tasks.delete(task_name.to_s) | |
end | |
end | |
def remove_task(name) | |
Rake.application.remove_task(name) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lib/tasks/db_schema_load.rake | |
require 'active_record' | |
load File.expand_path('../remove_task.rake', __FILE__) | |
remove_task('db:schema:load') | |
namespace :db do | |
namespace :schema do | |
desc 'Overrides the `db:schema:load` rake in order to load legacy schema before running the default `db:schema:load` task' | |
task load: [:load_config, :environment] do | |
ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, 'db/legacy.rb') | |
ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, ENV['SCHEMA']) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment