Commit 8fe10e642ad9b5d236d2b00cea475bdc519130c0

Authored by Jacob Vosmaer
1 parent 5d6e4bd2

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.
Showing 1 changed file with 2 additions and 0 deletions   Show diff stats
lib/backup/database.rb
... ... @@ -29,6 +29,8 @@ module Backup
29 29 print "Restoring MySQL database #{config['database']} ... "
30 30 system('mysql', *mysql_args, config['database'], in: db_file_name)
31 31 when "postgresql" then
  32 + puts "Destructively rebuilding database schema for RAILS_ENV #{Rails.env}"
  33 + Rake::Task["db:schema:load"].invoke
32 34 print "Restoring PostgreSQL database #{config['database']} ... "
33 35 pg_env
34 36 system('psql', config['database'], '-f', db_file_name)
... ...