diff options
author | Drew Blessing <drew@gitlab.com> | 2016-07-25 18:01:02 +0300 |
---|---|---|
committer | Drew Blessing <drew@gitlab.com> | 2016-07-26 05:16:54 +0300 |
commit | cfd103dbb55a37393966b764a55e0fe67b0232c3 (patch) | |
tree | 92b38bf8dca257c0e99bb3b89494975657e6c3f0 /lib/tasks | |
parent | 9fead2b8271c4f3bb6c04a596253f80b09de9caa (diff) |
Disable MySQL foreign key checks before dropping all tables
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/db.rake | 7 |
1 files changed, 7 insertions, 0 deletions
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' |