Merge branch 'mysql_validate_pre_truncate' into 'master'

Adds validation for schema_migration prior to truncate.

See merge request gitlab-org/gitlab-ce!6459
This commit is contained in:
Stan Hu 2019-02-06 05:07:48 +00:00
commit d0187de202

View file

@ -29,10 +29,11 @@ namespace :gitlab do
# If MySQL, turn off foreign key checks
connection.execute('SET FOREIGN_KEY_CHECKS=0') if Gitlab::Database.mysql?
tables = connection.tables
tables = connection.data_sources
# Removes the entry from the array
tables.delete 'schema_migrations'
# Truncate schema_migrations to ensure migrations re-run
connection.execute('TRUNCATE schema_migrations')
connection.execute('TRUNCATE schema_migrations') if connection.data_source_exists? 'schema_migrations'
# Drop tables with cascade to avoid dependent table errors
# PG: http://www.postgresql.org/docs/current/static/ddl-depend.html