per https://twitter.com/searls/status/1559543920673144834 -> https://blog.testdouble.com/posts/2022-08-15-migrating-postgres-extensions-to-the-heroku_ext_schema/
Created
October 12, 2022 14:15
-
-
Save bf4/cd917d4148f858a9774ceb48f58c7d10 to your computer and use it in GitHub Desktop.
Handling heroku_ext change
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
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