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