1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use if_not_exists instead of table_exists?

This commit is contained in:
Rafael Mendonça França 2021-12-08 23:25:02 +00:00
parent 6172f541d8
commit 8b6342e341
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948

View file

@ -1,14 +1,12 @@
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def change
unless table_exists?(:active_storage_variant_records)
# Use Active Record's configured type for primary key
create_table :active_storage_variant_records, id: primary_key_type do |t|
t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type
t.string :variation_digest, null: false
# Use Active Record's configured type for primary key
create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t|
t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type
t.string :variation_digest, null: false
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end