diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-23 15:11:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-23 15:11:54 +0300 |
commit | e10ea43772b9a6be150a074be7e26bfd6fa0380e (patch) | |
tree | 97bd1bb8fe3f656b5f2480d83b7dc9e369092d74 /lib/gitlab/database | |
parent | 1f8c5a116bebd31650ef414c7b762ba91b8cc251 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/database')
-rw-r--r-- | lib/gitlab/database/async_indexes/migration_helpers.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/gitlab/database/async_indexes/migration_helpers.rb b/lib/gitlab/database/async_indexes/migration_helpers.rb index f459c43e0ee..d14b6be3844 100644 --- a/lib/gitlab/database/async_indexes/migration_helpers.rb +++ b/lib/gitlab/database/async_indexes/migration_helpers.rb @@ -77,6 +77,33 @@ module Gitlab async_index end + def prepare_async_index_from_sql(table_name, index_name, definition) + Gitlab::Database::QueryAnalyzers::RestrictAllowedSchemas.require_ddl_mode! + + return unless async_index_creation_available? + + if index_name_exists?(table_name, index_name) + Gitlab::AppLogger.warn( + message: 'Index not prepared because it already exists', + table_name: table_name, + index_name: index_name) + + return + end + + async_index = Gitlab::Database::AsyncIndexes::PostgresAsyncIndex.find_or_create_by!(name: index_name) do |rec| + rec.table_name = table_name + rec.definition = definition + end + + Gitlab::AppLogger.info( + message: 'Prepared index for async creation', + table_name: async_index.table_name, + index_name: async_index.name) + + async_index + end + # Prepares an index for asynchronous destruction. # # Stores the index information in the postgres_async_indexes table to be removed later. The |