diff options
Diffstat (limited to 'lib/tasks/gitlab/db.rake')
-rw-r--r-- | lib/tasks/gitlab/db.rake | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index 425f66918b0..8a1809f9dfc 100644 --- a/lib/tasks/gitlab/db.rake +++ b/lib/tasks/gitlab/db.rake @@ -35,6 +35,11 @@ namespace :gitlab do # Truncate schema_migrations to ensure migrations re-run connection.execute('TRUNCATE schema_migrations') if connection.table_exists? 'schema_migrations' + # Drop any views + connection.views.each do |view| + connection.execute("DROP VIEW IF EXISTS #{connection.quote_table_name(view)} CASCADE") + end + # Drop tables with cascade to avoid dependent table errors # PG: http://www.postgresql.org/docs/current/static/ddl-depend.html # Add `IF EXISTS` because cascade could have already deleted a table. @@ -169,9 +174,21 @@ namespace :gitlab do desc 'reindex a regular (non-unique) index without downtime to eliminate bloat' task :reindex, [:index_name] => :environment do |_, args| - raise ArgumentError, 'must give the index name to reindex' unless args[:index_name] + unless Feature.enabled?(:database_reindexing, type: :ops) + puts "This feature (database_reindexing) is currently disabled.".color(:yellow) + exit + end + + indexes = if args[:index_name] + Gitlab::Database::PostgresIndex.by_identifier(args[:index_name]) + else + Gitlab::Database::Reindexing.candidate_indexes.random_few(2) + end - Gitlab::Database::ConcurrentReindex.new(args[:index_name], logger: Logger.new(STDOUT)).execute + Gitlab::Database::Reindexing.perform(indexes) + rescue => e + Gitlab::AppLogger.error(e) + raise end end end |