Commit cfd103db authored by Drew Blessing's avatar Drew Blessing

Disable MySQL foreign key checks before dropping all tables

parent 9fead2b8
...@@ -14,6 +14,7 @@ v 8.11.0 (unreleased) ...@@ -14,6 +14,7 @@ v 8.11.0 (unreleased)
v 8.10.2 (unreleased) v 8.10.2 (unreleased)
- User can now search branches by name. !5144 - User can now search branches by name. !5144
- Fix backup restore. !5459 - 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 - Use project ID in repository cache to prevent stale data from persisting across projects. !5460
v 8.10.1 v 8.10.1
......
...@@ -25,6 +25,10 @@ namespace :gitlab do ...@@ -25,6 +25,10 @@ namespace :gitlab do
desc 'Drop all tables' desc 'Drop all tables'
task :drop_tables => :environment do task :drop_tables => :environment do
connection = ActiveRecord::Base.connection 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 = connection.tables
tables.delete 'schema_migrations' tables.delete 'schema_migrations'
# Truncate schema_migrations to ensure migrations re-run # Truncate schema_migrations to ensure migrations re-run
...@@ -35,6 +39,9 @@ namespace :gitlab do ...@@ -35,6 +39,9 @@ namespace :gitlab do
# MySQL: http://dev.mysql.com/doc/refman/5.7/en/drop-table.html # MySQL: http://dev.mysql.com/doc/refman/5.7/en/drop-table.html
# Add `IF EXISTS` because cascade could have already deleted a table. # 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") } 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 end
desc 'Configures the database by running migrate, or by loading the schema and seeding if needed' desc 'Configures the database by running migrate, or by loading the schema and seeding if needed'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment