summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2014-10-28 18:52:21 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2014-10-28 18:52:21 +0100
commite00e67db42ea3e4b994160dbdc288a8effa14713 (patch)
treea9ac88d9482ef981453d4cda114049f7f2ff6c44 /lib
parent01441f544ecd32d6a820d2908413ff0cb6ff1245 (diff)
downloadgitlab-ce-e00e67db42ea3e4b994160dbdc288a8effa14713.tar.gz
Drop all Postgres sequences during backup restore
Diffstat (limited to 'lib')
-rw-r--r--lib/backup/database.rb1
-rw-r--r--lib/tasks/gitlab/db/drop_all_postgres_sequences.rake10
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/backup/database.rb b/lib/backup/database.rb
index d12d30a9110..ea659e3b605 100644
--- a/lib/backup/database.rb
+++ b/lib/backup/database.rb
@@ -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
diff --git a/lib/tasks/gitlab/db/drop_all_postgres_sequences.rake b/lib/tasks/gitlab/db/drop_all_postgres_sequences.rake
new file mode 100644
index 00000000000..e9cf0a9b5e8
--- /dev/null
+++ b/lib/tasks/gitlab/db/drop_all_postgres_sequences.rake
@@ -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