diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /db/post_migrate/20231109124031_ensure_id_uniqueness_for_p_ci_builds_v5.rb | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'db/post_migrate/20231109124031_ensure_id_uniqueness_for_p_ci_builds_v5.rb')
-rw-r--r-- | db/post_migrate/20231109124031_ensure_id_uniqueness_for_p_ci_builds_v5.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/db/post_migrate/20231109124031_ensure_id_uniqueness_for_p_ci_builds_v5.rb b/db/post_migrate/20231109124031_ensure_id_uniqueness_for_p_ci_builds_v5.rb new file mode 100644 index 00000000000..e3b082b41ad --- /dev/null +++ b/db/post_migrate/20231109124031_ensure_id_uniqueness_for_p_ci_builds_v5.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class EnsureIdUniquenessForPCiBuildsV5 < Gitlab::Database::Migration[2.2] + include Gitlab::Database::SchemaHelpers + + enable_lock_retries! + milestone '16.7' + + TABLE_NAME = :p_ci_builds + FUNCTION_NAME = :assign_p_ci_builds_id_value + TRIGGER_NAME = :assign_p_ci_builds_id_trigger + + def up + return if trigger_exists?(TABLE_NAME, TRIGGER_NAME) + + lock_tables(TABLE_NAME, :ci_builds) + + Gitlab::Database::PostgresPartitionedTable.each_partition(TABLE_NAME) do |partition| + drop_trigger(partition.identifier, TRIGGER_NAME, if_exists: true) + end + + create_trigger(TABLE_NAME, TRIGGER_NAME, FUNCTION_NAME, fires: 'BEFORE INSERT') + end + + def down + drop_trigger(TABLE_NAME, TRIGGER_NAME, if_exists: true) + return if trigger_exists?(:ci_builds, TRIGGER_NAME) + + Gitlab::Database::PostgresPartitionedTable.each_partition(TABLE_NAME) do |partition| + create_trigger(partition.identifier, TRIGGER_NAME, FUNCTION_NAME, fires: 'BEFORE INSERT') + end + end +end |