Drop all Postgres sequences during backup restore

This commit is contained in:
Jacob Vosmaer
2014-10-28 18:52:21 +01:00
parent 01441f544e
commit e00e67db42
2 changed files with 11 additions and 0 deletions
+1
View File
@@ -34,6 +34,7 @@ module Backup
# Drop all tables because PostgreSQL DB dumps do not contain DROP TABLE
# statements like MySQL.
Rake::Task["gitlab:db:drop_all_tables"].invoke
Rake::Task["gitlab:db:drop_all_postgres_sequences"].invoke
pg_env
system('psql', config['database'], '-f', db_file_name)
end
@@ -0,0 +1,10 @@
namespace :gitlab do
namespace :db do
task drop_all_postgres_sequences: :environment do
connection = ActiveRecord::Base.connection
connection.execute("SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';").each do |sequence|
connection.execute("DROP SEQUENCE #{sequence['relname']}")
end
end
end
end