Skip to content

Instantly share code, notes, and snippets.

@bf4
Created October 12, 2022 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bf4/cd917d4148f858a9774ceb48f58c7d10 to your computer and use it in GitHub Desktop.
Save bf4/cd917d4148f858a9774ceb48f58c7d10 to your computer and use it in GitHub Desktop.
Handling heroku_ext change
require "active_record"
require "active_record/tasks/database_tasks"
module HackDatabaseTasks
def dump_schema(db_config, format = ActiveRecord.schema_format) # :nodoc:
super.tap do
filename = schema_dump_path(db_config, format)
path = "db/structure.sql"
next unless filename.include?(path)
IO.write(filename, File.open(filename) { |f|
f.read.gsub "CREATE SCHEMA heroku_ext;", <<~SQL.chomp
-- WARNING: CUSTOM HACK!
-- Add "IF NOT EXISTS" to only create schema if not created by Heroku
CREATE SCHEMA IF NOT EXISTS heroku_ext;
SQL
})
end
end
end
ActiveRecord::Tasks::DatabaseTasks.prepend(HackDatabaseTasks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment