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

Merge branch '422835-sync-index-creation1' into 'master'

Sync create indexes and prepare FK for p_ci_builds auto_canceled_by_id

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142766



Merged-by: default avatarMarius Bobin <mbobin@gitlab.com>
Approved-by: default avatarEthan Urie <eurie@gitlab.com>
Approved-by: default avatarMarius Bobin <mbobin@gitlab.com>
Approved-by: default avatarDylan Griffith <dyl.griffith@gmail.com>
Reviewed-by: default avatarTianwen Chen <tchen@gitlab.com>
Co-authored-by: default avatarTianwen Chen <tchen@gitlab.com>
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true
class SyncIndexForPCiBuildsPart1 < Gitlab::Database::Migration[2.2]
include Gitlab::Database::PartitioningMigrationHelpers
milestone '16.9'
TABLE_NAME = :p_ci_builds
INDEXES = [
['p_ci_builds_auto_canceled_by_id_bigint_idx', [:auto_canceled_by_id_convert_to_bigint],
{ where: "auto_canceled_by_id_convert_to_bigint IS NOT NULL" }],
['p_ci_builds_commit_id_bigint_status_type_idx', [:commit_id_convert_to_bigint, :status, :type], {}],
['p_ci_builds_commit_id_bigint_type_name_ref_idx', [:commit_id_convert_to_bigint, :type, :name, :ref], {}]
]
disable_ddl_transaction!
def up
INDEXES.each do |index_name, columns, options|
add_concurrent_partitioned_index(TABLE_NAME, columns, name: index_name, **options)
end
end
def down
INDEXES.each do |index_name, _columns, _options|
remove_concurrent_partitioned_index_by_name(TABLE_NAME, index_name)
end
end
end
# frozen_string_literal: true
class AddFkForAutoCanceledByIdBigintBetweenPCiBuildsAndCiPipelines < Gitlab::Database::Migration[2.2]
include Gitlab::Database::PartitioningMigrationHelpers
milestone '16.9'
disable_ddl_transaction!
SOURCE_TABLE_NAME = :p_ci_builds
TARGET_TABLE_NAME = :ci_pipelines
COLUMN = :auto_canceled_by_id_convert_to_bigint
TARGET_COLUMN = :id
FK_NAME = :fk_dd3c83bdee
def up
add_concurrent_partitioned_foreign_key(
SOURCE_TABLE_NAME, TARGET_TABLE_NAME,
column: [COLUMN],
target_column: [TARGET_COLUMN],
validate: false,
reverse_lock_order: true,
on_delete: :nullify,
name: FK_NAME
)
prepare_partitioned_async_foreign_key_validation(
SOURCE_TABLE_NAME, [COLUMN],
name: FK_NAME
)
end
def down
unprepare_partitioned_async_foreign_key_validation(
SOURCE_TABLE_NAME, [COLUMN],
name: FK_NAME
)
Gitlab::Database::PostgresPartitionedTable.each_partition(SOURCE_TABLE_NAME) do |partition|
with_lock_retries do
remove_foreign_key_if_exists(
partition.identifier, TARGET_TABLE_NAME,
name: FK_NAME,
reverse_lock_order: true
)
end
end
with_lock_retries do
remove_foreign_key_if_exists(
SOURCE_TABLE_NAME, TARGET_TABLE_NAME,
name: FK_NAME,
reverse_lock_order: true
)
end
end
end
81c0af94a19346f9f01c4191f37a579e4825a0d06efb42c714e6b835a114544a
\ No newline at end of file
99c24a58185c81b7b4d2c0fb0b0fdfa3505035a9de5474f71b9a482c8c93f537
\ No newline at end of file
......@@ -32529,6 +32529,10 @@ CREATE INDEX idx_vulnerability_reads_project_id_scanner_id_vulnerability_id ON v
 
CREATE UNIQUE INDEX idx_work_item_types_on_namespace_id_and_name_null_namespace ON work_item_types USING btree (btrim(lower(name)), ((namespace_id IS NULL))) WHERE (namespace_id IS NULL);
 
CREATE INDEX p_ci_builds_commit_id_bigint_status_type_idx ON ONLY p_ci_builds USING btree (commit_id_convert_to_bigint, status, type);
CREATE INDEX index_8c07a79c70 ON ci_builds USING btree (commit_id_convert_to_bigint, status, type);
CREATE INDEX index_abuse_events_on_abuse_report_id ON abuse_events USING btree (abuse_report_id);
 
CREATE INDEX index_abuse_events_on_category_and_source ON abuse_events USING btree (category, source);
......@@ -33739,6 +33743,10 @@ CREATE UNIQUE INDEX index_external_audit_event_destinations_on_namespace_id ON a
 
CREATE UNIQUE INDEX index_external_pull_requests_on_project_and_branches ON external_pull_requests USING btree (project_id, source_branch, target_branch);
 
CREATE INDEX p_ci_builds_commit_id_bigint_type_name_ref_idx ON ONLY p_ci_builds USING btree (commit_id_convert_to_bigint, type, name, ref);
CREATE INDEX index_feafb4d370 ON ci_builds USING btree (commit_id_convert_to_bigint, type, name, ref);
CREATE UNIQUE INDEX index_feature_flag_scopes_on_flag_id_and_environment_scope ON operations_feature_flag_scopes USING btree (feature_flag_id, environment_scope);
 
CREATE UNIQUE INDEX index_feature_flags_clients_on_project_id_and_token_encrypted ON operations_feature_flags_clients USING btree (project_id, token_encrypted);
......@@ -33747,6 +33755,10 @@ CREATE UNIQUE INDEX index_feature_gates_on_feature_key_and_key_and_value ON feat
 
CREATE UNIQUE INDEX index_features_on_key ON features USING btree (key);
 
CREATE INDEX p_ci_builds_auto_canceled_by_id_bigint_idx ON ONLY p_ci_builds USING btree (auto_canceled_by_id_convert_to_bigint) WHERE (auto_canceled_by_id_convert_to_bigint IS NOT NULL);
CREATE INDEX index_ffe1233676 ON ci_builds USING btree (auto_canceled_by_id_convert_to_bigint) WHERE (auto_canceled_by_id_convert_to_bigint IS NOT NULL);
CREATE INDEX index_for_security_scans_scan_type ON security_scans USING btree (scan_type, project_id, pipeline_id) WHERE (status = 1);
 
CREATE INDEX index_for_status_per_branch_per_project ON merge_trains USING btree (target_project_id, target_branch, status);
......@@ -38031,6 +38043,8 @@ ALTER INDEX p_ci_builds_pkey ATTACH PARTITION ci_builds_pkey;
 
ALTER INDEX p_ci_pipeline_variables_pkey ATTACH PARTITION ci_pipeline_variables_pkey;
 
ALTER INDEX p_ci_builds_commit_id_bigint_status_type_idx ATTACH PARTITION index_8c07a79c70;
ALTER INDEX p_ci_builds_metadata_build_id_idx ATTACH PARTITION index_ci_builds_metadata_on_build_id_and_has_exposed_artifacts;
 
ALTER INDEX p_ci_builds_metadata_build_id_id_idx ATTACH PARTITION index_ci_builds_metadata_on_build_id_and_id_and_interruptible;
......@@ -38075,6 +38089,10 @@ ALTER INDEX p_ci_builds_project_id_status_idx ATTACH PARTITION index_ci_builds_p
 
ALTER INDEX p_ci_builds_runner_id_idx ATTACH PARTITION index_ci_builds_runner_id_running;
 
ALTER INDEX p_ci_builds_commit_id_bigint_type_name_ref_idx ATTACH PARTITION index_feafb4d370;
ALTER INDEX p_ci_builds_auto_canceled_by_id_bigint_idx ATTACH PARTITION index_ffe1233676;
ALTER INDEX p_ci_builds_user_id_name_idx ATTACH PARTITION index_partial_ci_builds_on_user_id_name_parser_features;
 
ALTER INDEX p_ci_pipeline_variables_pipeline_id_key_partition_id_idx ATTACH PARTITION index_pipeline_variables_on_pipeline_id_key_partition_id_unique;
......@@ -39187,6 +39205,9 @@ ALTER TABLE ONLY workspaces
ALTER TABLE ONLY epics
ADD CONSTRAINT fk_dccd3f98fc FOREIGN KEY (assignee_id) REFERENCES users(id) ON DELETE SET NULL;
 
ALTER TABLE ONLY ci_builds
ADD CONSTRAINT fk_dd3c83bdee FOREIGN KEY (auto_canceled_by_id_convert_to_bigint) REFERENCES ci_pipelines(id) ON DELETE SET NULL NOT VALID;
ALTER TABLE ONLY protected_branches
ADD CONSTRAINT fk_de9216e774 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
 
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册