Skip to content
代码片段 群组 项目
未验证 提交 5903e80a 编辑于 作者: Tianwen Chen's avatar Tianwen Chen 提交者: GitLab
浏览文件

Prepare async index for auto_canceled_by_id_convert_to_bigint

As titled, this is the first step of creating indexes asynchronously.
See guideline at https://docs.gitlab.com/ee/development/database/adding_database_indexes.html#schedule-the-index-to-be-created

It's to schedule the index creation for
`p_ci_builds.auto_canceled_by_id_convert_to_bigint`
as the foreign key constraint requires the index
so that we can later swap `auto_canceled_by_id_convert_to_bigint` with `auto_canceled_by_id`

Changelog: added
上级 bb7473c1
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true
class EnsureBackfillForCiBuildsIntegerColumnsIsFinished < Gitlab::Database::Migration[2.2]
include Gitlab::Database::MigrationHelpers::ConvertToBigint
milestone '16.9'
restrict_gitlab_migration gitlab_schema: :gitlab_ci
disable_ddl_transaction!
TABLE_NAME = :ci_builds
COLUMN_NAMES = %w[
auto_canceled_by_id
commit_id
erased_by_id
project_id
runner_id
trigger_request_id
upstream_pipeline_id
user_id
]
BIGINT_COLUMN_NAMES = COLUMN_NAMES.map { |name| "#{name}_convert_to_bigint" }
def up
ensure_batched_background_migration_is_finished(
job_class_name: 'CopyColumnUsingBackgroundMigrationJob',
table_name: TABLE_NAME,
column_name: 'id',
job_arguments: [COLUMN_NAMES, BIGINT_COLUMN_NAMES]
)
end
def down
# no-op
end
end
# frozen_string_literal: true
class PrepareAsyncIndexesForPCiBuildsAutoCanceledById < Gitlab::Database::Migration[2.2]
include Gitlab::Database::PartitioningMigrationHelpers
milestone '16.9'
disable_ddl_transaction!
INDEX_NAME = "p_ci_builds_auto_canceled_by_id_bigint_idx"
TABLE_NAME = :p_ci_builds
COLUMN_NAME = :auto_canceled_by_id_convert_to_bigint
WHERE_CLAUSE = "auto_canceled_by_id_convert_to_bigint IS NOT NULL"
def up
Gitlab::Database::PostgresPartitionedTable.each_partition(TABLE_NAME) do |partition|
index_name = generated_index_name(partition.identifier, INDEX_NAME)
prepare_async_index partition.identifier, COLUMN_NAME, name: index_name, where: WHERE_CLAUSE
end
end
def down
Gitlab::Database::PostgresPartitionedTable.each_partition(TABLE_NAME) do |partition|
index_name = generated_index_name(partition.identifier, INDEX_NAME)
unprepare_async_index partition.identifier, COLUMN_NAME, name: index_name, where: WHERE_CLAUSE
end
end
end
# frozen_string_literal: true
class PrepareAsyncIndexesForPCiBuildsCommitIdPart1 < Gitlab::Database::Migration[2.2]
include Gitlab::Database::PartitioningMigrationHelpers
milestone '16.9'
disable_ddl_transaction!
INDEXES = [
[[:commit_id_convert_to_bigint, :status, :type], "p_ci_builds_commit_id_bigint_status_type_idx"],
[[:commit_id_convert_to_bigint, :type, :name, :ref], "p_ci_builds_commit_id_bigint_type_name_ref_idx"]
]
TABLE_NAME = :p_ci_builds
def up
Gitlab::Database::PostgresPartitionedTable.each_partition(TABLE_NAME) do |partition|
INDEXES.each do |columns, routing_table_index_name|
index_name = generated_index_name(partition.identifier, routing_table_index_name)
prepare_async_index partition.identifier, columns, name: index_name
end
end
end
def down
Gitlab::Database::PostgresPartitionedTable.each_partition(TABLE_NAME) do |partition|
INDEXES.each do |columns, routing_table_index_name|
index_name = generated_index_name(partition.identifier, routing_table_index_name)
unprepare_async_index partition.identifier, columns, name: index_name
end
end
end
end
a404dcf1d57886af351b696f8cbc451e7e81d69618a6bd3c30e1676a99172ca6
\ No newline at end of file
3feac709d7c1e6d911068d096e876fcbdace5c3e47036a3c8d9bb347a4d6f4ba
\ No newline at end of file
93164c045f7581f7dbcd606f2217514344bf2fdb72a6ece05241214e7a7f3c9d
\ No newline at end of file
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册