diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /lib/tasks/gitlab/db.rake | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'lib/tasks/gitlab/db.rake')
-rw-r--r-- | lib/tasks/gitlab/db.rake | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index 425f66918b0..a3f20f31f64 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. @@ -60,6 +65,19 @@ namespace :gitlab do end end + desc 'GitLab | DB | Run database migrations and print `unattended_migrations_completed` if action taken' + task unattended: :environment do + no_database = !ActiveRecord::Base.connection.schema_migration.table_exists? + needs_migrations = ActiveRecord::Base.connection.migration_context.needs_migration? + + if no_database || needs_migrations + Rake::Task['gitlab:db:configure'].invoke + puts "unattended_migrations_completed" + else + puts "unattended_migrations_static" + end + end + desc 'GitLab | DB | Checks if migrations require downtime or not' task :downtime_check, [:ref] => :environment do |_, args| abort 'You must specify a Git reference to compare with' unless args[:ref] @@ -169,9 +187,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 |