summaryrefslogtreecommitdiff
path: root/lib/backup/database.rb
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2014-02-26 18:26:31 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2014-02-26 18:26:31 +0100
commit8fe10e642ad9b5d236d2b00cea475bdc519130c0 (patch)
treeedf396ff9b310ab246f174d2904e78073d8d07c4 /lib/backup/database.rb
parent5d6e4bd2d8d2e45407bb437e5b22656cffedc15a (diff)
downloadgitlab-ce-8fe10e642ad9b5d236d2b00cea475bdc519130c0.tar.gz
Empty the database during Postgres backup restore
The expected behavior during a GitLab backup restore is to overwrite existing database data. This works for MySQL because the output of mysqldump contains 'DROP TABLE IF EXISTS' statements. pg_dump on the other hand assumes that one will restore into an empty database. When this is not the case, during the restore with psql some of the data will be skipped if existing data is 'in the way'. By first invoking `rake db:schema:load` during a Postgres GitLab backup restore, we make sure that all important data is correctly restored.
Diffstat (limited to 'lib/backup/database.rb')
-rw-r--r--lib/backup/database.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/backup/database.rb b/lib/backup/database.rb
index ebb4f289c52..6552f45ff0b 100644
--- a/lib/backup/database.rb
+++ b/lib/backup/database.rb
@@ -29,6 +29,8 @@ module Backup
print "Restoring MySQL database #{config['database']} ... "
system('mysql', *mysql_args, config['database'], in: db_file_name)
when "postgresql" then
+ puts "Destructively rebuilding database schema for RAILS_ENV #{Rails.env}"
+ Rake::Task["db:schema:load"].invoke
print "Restoring PostgreSQL database #{config['database']} ... "
pg_env
system('psql', config['database'], '-f', db_file_name)