Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-04 06:14:22 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-04 06:14:22 +0300
commit0555f8b0429486b14e36f92152587030db33708c (patch)
treee4175b09dfa73b9c78f6167f5e23b2bfd8909eae /db
parente52198c83629b4e880f7851f9a625cad651c3819 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20230328184031_swap_sent_notifications_id_columns.rb59
-rw-r--r--db/schema_migrations/202303281840311
-rw-r--r--db/structure.sql4
3 files changed, 62 insertions, 2 deletions
diff --git a/db/post_migrate/20230328184031_swap_sent_notifications_id_columns.rb b/db/post_migrate/20230328184031_swap_sent_notifications_id_columns.rb
new file mode 100644
index 00000000000..a2a0751c38a
--- /dev/null
+++ b/db/post_migrate/20230328184031_swap_sent_notifications_id_columns.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+# See https://docs.gitlab.com/ee/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class SwapSentNotificationsIdColumns < Gitlab::Database::Migration[2.1]
+ include Gitlab::Database::MigrationHelpers::ConvertToBigint
+
+ disable_ddl_transaction!
+
+ TABLE_NAME = :sent_notifications
+ COLUMN_NAME = :id_convert_to_bigint
+ INDEX_NAME = :index_sent_notifications_on_id_convert_to_bigint
+
+ def up
+ return unless should_run?
+
+ swap
+ end
+
+ def down
+ return unless should_run?
+
+ swap
+ end
+
+ def swap
+ add_concurrent_index TABLE_NAME, COLUMN_NAME, unique: true, name: INDEX_NAME
+
+ with_lock_retries(raise_on_exhaustion: true) do
+ execute "LOCK TABLE #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE"
+
+ # Swap Columns
+ temp_name = quote_column_name(:id_tmp)
+ id_name = quote_column_name(:id)
+ id_convert_to_bigint_name = quote_column_name(COLUMN_NAME)
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_name} TO #{temp_name}"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{id_convert_to_bigint_name} TO #{id_name}"
+ execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN #{temp_name} TO #{id_convert_to_bigint_name}"
+
+ # Reset trigger
+ function_name = Gitlab::Database::UnidirectionalCopyTrigger.on_table(TABLE_NAME, connection: connection)
+ .name(:id, :id_convert_to_bigint)
+ execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL"
+
+ execute "ALTER SEQUENCE #{TABLE_NAME}_id_seq OWNED BY #{TABLE_NAME}.id"
+ change_column_default TABLE_NAME, :id, -> { "nextval('#{TABLE_NAME}_id_seq'::regclass)" }
+ change_column_default TABLE_NAME, :id_convert_to_bigint, 0
+
+ execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT #{TABLE_NAME}_pkey CASCADE"
+ rename_index TABLE_NAME, INDEX_NAME, "#{TABLE_NAME}_pkey"
+ execute "ALTER TABLE #{TABLE_NAME} ADD CONSTRAINT #{TABLE_NAME}_pkey PRIMARY KEY USING INDEX #{TABLE_NAME}_pkey"
+ end
+ end
+
+ def should_run?
+ com_or_dev_or_test_but_not_jh?
+ end
+end
diff --git a/db/schema_migrations/20230328184031 b/db/schema_migrations/20230328184031
new file mode 100644
index 00000000000..2a099b60ba1
--- /dev/null
+++ b/db/schema_migrations/20230328184031
@@ -0,0 +1 @@
+04dcd7983b02b2c97d64be9c55a1bdf921c39e5c5026ce086e8cc06932fd8344 \ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index ed121f987ea..99e2d492c89 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -22258,7 +22258,7 @@ CREATE SEQUENCE self_managed_prometheus_alert_events_id_seq
ALTER SEQUENCE self_managed_prometheus_alert_events_id_seq OWNED BY self_managed_prometheus_alert_events.id;
CREATE TABLE sent_notifications (
- id integer NOT NULL,
+ id_convert_to_bigint integer DEFAULT 0 NOT NULL,
project_id integer,
noteable_id integer,
noteable_type character varying,
@@ -22269,7 +22269,7 @@ CREATE TABLE sent_notifications (
note_type character varying,
"position" text,
in_reply_to_discussion_id character varying,
- id_convert_to_bigint bigint DEFAULT 0 NOT NULL
+ id bigint NOT NULL
);
CREATE SEQUENCE sent_notifications_id_seq