Commit bd6faf2b authored by Toon Claes's avatar Toon Claes

Add creator_id column to custom_emoji table

To keep track of who added a the custom emoji add a foreign key to the
user id.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/284641
parent f11bf3bb
---
title: Add creator to custom emoji
merge_request: 53879
author:
type: changed
# frozen_string_literal: true
class AddCreatorIdToCustomEmoji < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
# Custom Emoji is at the moment behind a default-disabled feature flag. It
# will be unlikely there are any records in this table, but to able to
# ensure a not-null constraint delete any existing rows.
# Roll-out issue: https://gitlab.com/gitlab-org/gitlab/-/issues/231317
execute 'DELETE FROM custom_emoji'
add_reference :custom_emoji, # rubocop:disable Migration/AddReference
:creator,
index: true,
null: false, # rubocop:disable Rails/NotNullColumn
foreign_key: false # FK is added in 20210219100137
end
def down
remove_reference :custom_emoji, :creator
end
end
# frozen_string_literal: true
class AddCreatorForeignKeyToCustomEmoji < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
FK_NAME = 'fk_custom_emoji_creator_id'
disable_ddl_transaction!
def up
add_concurrent_foreign_key :custom_emoji, :users,
on_delete: :cascade,
column: :creator_id,
name: FK_NAME
end
def down
with_lock_retries do
remove_foreign_key :custom_emoji, name: FK_NAME
end
end
end
7c368cad497ccfd86c6a92e2edfec1d2a16879eb749184b1d20c5ab4c702b974
\ No newline at end of file
be2ddc15e16d7d59bd050a60faaa0b6941d94ba7c47a88be473bcf3a17bb2763
\ No newline at end of file
......@@ -11607,6 +11607,7 @@ CREATE TABLE custom_emoji (
name text NOT NULL,
file text NOT NULL,
external boolean DEFAULT true NOT NULL,
creator_id bigint NOT NULL,
CONSTRAINT check_8c586dd507 CHECK ((char_length(name) <= 36)),
CONSTRAINT check_dd5d60f1fb CHECK ((char_length(file) <= 255))
);
......@@ -21967,6 +21968,8 @@ CREATE INDEX index_csv_issue_imports_on_project_id ON csv_issue_imports USING bt
CREATE INDEX index_csv_issue_imports_on_user_id ON csv_issue_imports USING btree (user_id);
CREATE INDEX index_custom_emoji_on_creator_id ON custom_emoji USING btree (creator_id);
CREATE UNIQUE INDEX index_custom_emoji_on_namespace_id_and_name ON custom_emoji USING btree (namespace_id, name);
CREATE UNIQUE INDEX index_daily_build_group_report_results_unique_columns ON ci_daily_build_group_report_results USING btree (project_id, ref_path, date, group_name);
......@@ -24686,6 +24689,9 @@ ALTER TABLE ONLY todos
ALTER TABLE ONLY geo_event_log
ADD CONSTRAINT fk_cff7185ad2 FOREIGN KEY (reset_checksum_event_id) REFERENCES geo_reset_checksum_events(id) ON DELETE CASCADE;
ALTER TABLE ONLY custom_emoji
ADD CONSTRAINT fk_custom_emoji_creator_id FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY bulk_import_entities
ADD CONSTRAINT fk_d06d023c30 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment