Commit 48bd8a7e16f2c151472f76f82adc3fd28ce04ba2

Authored by Dmitriy Zaporozhets
2 parents e6fbf79b 77b57c11

Merge remote-tracking branch 'origin/rake_drop_tables'

Conflicts:
	CHANGELOG
CHANGELOG
... ... @@ -3,6 +3,7 @@ v 6.8.0
3 3 - 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)
4 4 - Make user search case-insensitive (Christopher Arnold)
5 5 - Remove omniauth-ldap nickname bug workaround
  6 + - Drop all tables before restoring a Postgres backup
6 7  
7 8 v 6.7.2
8 9 - Fix upgrader script
... ...
lib/backup/database.rb
... ... @@ -29,9 +29,10 @@ 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
34 32 print "Restoring PostgreSQL database #{config['database']} ... "
  33 + # Drop all tables because PostgreSQL DB dumps do not contain DROP TABLE
  34 + # statements like MySQL.
  35 + Rake::Task["gitlab:db:drop_all_tables"].invoke
35 36 pg_env
36 37 system('psql', config['database'], '-f', db_file_name)
37 38 end
... ...
lib/tasks/gitlab/db/drop_all_tables.rake 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +namespace :gitlab do
  2 + namespace :db do
  3 + task drop_all_tables: :environment do
  4 + connection = ActiveRecord::Base.connection
  5 + connection.tables.each do |table|
  6 + connection.drop_table(table)
  7 + end
  8 + end
  9 + end
  10 +end
... ...