diff options
Diffstat (limited to 'db/migrate/20200406172135_add_not_null_constraint_on_file_store_to_uploads.rb')
-rw-r--r-- | db/migrate/20200406172135_add_not_null_constraint_on_file_store_to_uploads.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/db/migrate/20200406172135_add_not_null_constraint_on_file_store_to_uploads.rb b/db/migrate/20200406172135_add_not_null_constraint_on_file_store_to_uploads.rb new file mode 100644 index 00000000000..aa498ba9c89 --- /dev/null +++ b/db/migrate/20200406172135_add_not_null_constraint_on_file_store_to_uploads.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class AddNotNullConstraintOnFileStoreToUploads < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + CONSTRAINT_NAME = 'uploads_store_not_null' + DOWNTIME = false + + def up + with_lock_retries do + execute <<~SQL + ALTER TABLE uploads ADD CONSTRAINT #{CONSTRAINT_NAME} CHECK (store IS NOT NULL) NOT VALID; + SQL + end + end + + def down + with_lock_retries do + execute <<~SQL + ALTER TABLE uploads DROP CONSTRAINT IF EXISTS #{CONSTRAINT_NAME}; + SQL + end + end +end |