diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | lib/backup/database.rb | 5 | ||||
-rw-r--r-- | lib/tasks/gitlab/db/drop_all_tables.rake | 10 |
3 files changed, 14 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG index 0224d950283..19219915789 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ v 6.8.0 - Enabled GZip Compression for assets in example Nginx, make sure that Nginx is compiled with --with-http_gzip_static_module flag (this is default in Ubuntu) - Make user search case-insensitive (Christopher Arnold) - Remove omniauth-ldap nickname bug workaround + - Drop all tables before restoring a Postgres backup v 6.7.2 - Fix upgrader script diff --git a/lib/backup/database.rb b/lib/backup/database.rb index 6552f45ff0b..7b6908ccad8 100644 --- a/lib/backup/database.rb +++ b/lib/backup/database.rb @@ -29,9 +29,10 @@ 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']} ... " + # Drop all tables because PostgreSQL DB dumps do not contain DROP TABLE + # statements like MySQL. + Rake::Task["gitlab:db:drop_all_tables"].invoke pg_env system('psql', config['database'], '-f', db_file_name) end diff --git a/lib/tasks/gitlab/db/drop_all_tables.rake b/lib/tasks/gitlab/db/drop_all_tables.rake new file mode 100644 index 00000000000..a66030ab93a --- /dev/null +++ b/lib/tasks/gitlab/db/drop_all_tables.rake @@ -0,0 +1,10 @@ +namespace :gitlab do + namespace :db do + task drop_all_tables: :environment do + connection = ActiveRecord::Base.connection + connection.tables.each do |table| + connection.drop_table(table) + end + end + end +end |