Skip to content

Instantly share code, notes, and snippets.

@roalcantara
Last active April 29, 2019 08:58
Show Gist options
  • Save roalcantara/a53083a313ecf2ba9aa65596da4cee13 to your computer and use it in GitHub Desktop.
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
#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
#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