Skip to content

Commit

Permalink
Use if_not_exists instead of table_exists?
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Dec 8, 2021
1 parent 6172f54 commit 8b6342e
Showing 1 changed file with 6 additions and 8 deletions.
@@ -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

Expand Down

0 comments on commit 8b6342e

Please sign in to comment.