From 56c267e52cd84c82eec1319a5847016ed9dc37cc Mon Sep 17 00:00:00 2001 From: Jose Torres Date: Wed, 21 Sep 2016 21:54:09 +0000 Subject: Fix MySQL error when truncating a table that doesn't exist This adds a conditional statement before truncating the `schema_migrations` table. This comit also ports this code to Rails 5. --- lib/tasks/gitlab/db.rake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index 74cd70c6e9f..b94b21775ee 100644 --- a/lib/tasks/gitlab/db.rake +++ b/lib/tasks/gitlab/db.rake @@ -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 -- cgit v1.2.1