Skip to content

Instantly share code, notes, and snippets.

@aileron
Created November 18, 2024 02:52
Show Gist options
  • Save aileron/ecf0c121f1093542db10804aac9f1b61 to your computer and use it in GitHub Desktop.
Save aileron/ecf0c121f1093542db10804aac9f1b61 to your computer and use it in GitHub Desktop.
ridgepole rake task
module RidgepoleTask
extend Rake::DSL
namespace :ridgepole do
desc "Exec Apply Dry Run"
task(apply_dry_run: :environment) { ridgepole "--apply --dry-run" }
desc "Exec Apply"
task(apply: :environment) { ridgepole "--apply --drop-table" }
desc "Exec Export Schemafile"
task(export: :environment) { ridgepole "--export -o" }
end
def self.ridgepole(option) = system(
[
ENV["DATABASE_URL"]&.then { |url| "DATABASE_URL='#{url}' " },
"bundle exec ridgepole -c #{Rails.root.join('config/database.yml')} -E #{Rails.env}",
"--dump-with-default-fk-name -f #{Rails.root.join('Schemafile')} #{option}"
].compact.join
).tap { |cmd| puts cmd }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment