summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-07-26 08:00:12 +0000
committerRémy Coutable <remy@rymai.me>2016-07-26 08:00:12 +0000
commit4bf20d677b2ec3bffae9fe2ca1abbbc0429b6b28 (patch)
tree3d36a1b1cb0c916a760743936d445bd3b4e8be10
parent68162ba900f1b9003fa3d07613333f201be8154a (diff)
parentcfd103dbb55a37393966b764a55e0fe67b0232c3 (diff)
downloadgitlab-ce-4bf20d677b2ec3bffae9fe2ca1abbbc0429b6b28.tar.gz
Merge branch 'mysql_drop_all_tables' into 'master'
Disable MySQL foreign key checks before dropping all tables Fixes #20237. Disables MySQL foreign key checks before dropping all tables in a restore. MySQL doesn't honor `CASCADE` without a special flag when the database/tables are created. In order to drop the tables we need to disable foreign key checks. After the drop, re-enable the key checks. WIP: Pending confirmation from customer that this fix works. See merge request !5472
-rw-r--r--CHANGELOG1
-rw-r--r--lib/tasks/gitlab/db.rake7
2 files changed, 8 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 534f57cb08e..4f542a86ce8 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -16,6 +16,7 @@ v 8.11.0 (unreleased)
v 8.10.2 (unreleased)
- User can now search branches by name. !5144
- Fix backup restore. !5459
+ - Disable MySQL foreign key checks before dropping all tables. !5472
- Use project ID in repository cache to prevent stale data from persisting across projects. !5460
v 8.10.1
diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake
index 0ec19e1a625..7c96bc864ce 100644
--- a/lib/tasks/gitlab/db.rake
+++ b/lib/tasks/gitlab/db.rake
@@ -25,6 +25,10 @@ namespace :gitlab do
desc 'Drop all tables'
task :drop_tables => :environment do
connection = ActiveRecord::Base.connection
+
+ # If MySQL, turn off foreign key checks
+ connection.execute('SET FOREIGN_KEY_CHECKS=0') if Gitlab::Database.mysql?
+
tables = connection.tables
tables.delete 'schema_migrations'
# Truncate schema_migrations to ensure migrations re-run
@@ -35,6 +39,9 @@ namespace :gitlab do
# MySQL: http://dev.mysql.com/doc/refman/5.7/en/drop-table.html
# Add `IF EXISTS` because cascade could have already deleted a table.
tables.each { |t| connection.execute("DROP TABLE IF EXISTS #{connection.quote_table_name(t)} CASCADE") }
+
+ # If MySQL, re-enable foreign key checks
+ connection.execute('SET FOREIGN_KEY_CHECKS=1') if Gitlab::Database.mysql?
end
desc 'Configures the database by running migrate, or by loading the schema and seeding if needed'