-
-
Save leylaKapi/cc8aaeb688fdfb39766f20424e38c211 to your computer and use it in GitHub Desktop.
Fix 'ERROR: must be owner of extension plpgsql' complaints from Postgresql when dumping and reloading structure.sql
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
# Put this in your Rails app's lib/tasks directory | |
namespace :db do | |
desc "Fix 'ERROR: must be owner of extension plpgsql' complaints from Postgresql" | |
task :fix_psql_dump do |task| | |
filename = ENV['DB_STRUCTURE'] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "structure.sql") | |
sql = File.read(filename) | |
sql.sub!(/(CREATE EXTENSION IF NOT EXISTS plpgsql)/, '-- \1') | |
sql.sub!(/(COMMENT ON EXTENSION plpgsql)/, '-- \1') | |
File.open(filename, 'w') do |f| | |
f.write(sql) | |
end | |
task.reenable | |
end | |
end | |
Rake::Task["db:structure:dump"].enhance do | |
Rake::Task["db:fix_psql_dump"].invoke | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment