diff options
Diffstat (limited to 'db/migrate/20220722150231_create_function_gitlab_schema_prevent_write.rb')
-rw-r--r-- | db/migrate/20220722150231_create_function_gitlab_schema_prevent_write.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/db/migrate/20220722150231_create_function_gitlab_schema_prevent_write.rb b/db/migrate/20220722150231_create_function_gitlab_schema_prevent_write.rb new file mode 100644 index 00000000000..d25923923f2 --- /dev/null +++ b/db/migrate/20220722150231_create_function_gitlab_schema_prevent_write.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class CreateFunctionGitlabSchemaPreventWrite < Gitlab::Database::Migration[2.0] + TRIGGER_FUNCTION_NAME = 'gitlab_schema_prevent_write' + + enable_lock_retries! + + # This migration is only to make sure that the lock-write trigger function + # matches what we already have on staging/production for Gitlab.com + + def up + execute(<<~SQL) + CREATE OR REPLACE FUNCTION #{TRIGGER_FUNCTION_NAME}() + RETURNS TRIGGER AS + $$ + BEGIN + RAISE EXCEPTION 'Table: "%" is write protected within this Gitlab database.', TG_TABLE_NAME + USING ERRCODE = 'modifying_sql_data_not_permitted', + HINT = 'Make sure you are using the right database connection'; + END + $$ LANGUAGE PLPGSQL + SQL + end + + def down + return if Gitlab.com? + + execute(<<~SQL) + DROP FUNCTION #{TRIGGER_FUNCTION_NAME} + SQL + end +end |