Skip to content

Instantly share code, notes, and snippets.

@bonkydog
Last active December 27, 2017 11:38
Show Gist options
  • Save bonkydog/353b8bc5421d03a2a8e0 to your computer and use it in GitHub Desktop.
Save bonkydog/353b8bc5421d03a2a8e0 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
# 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