Skip to content

Commit 0b5bb41

Browse files
committed
Minor improvements to the create active storage db files migration
1 parent 2d09f06 commit 0b5bb41

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

db/migrate/20200702202022_create_active_storage_db_files.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22

33
class CreateActiveStorageDBFiles < ActiveRecord::Migration[6.0]
44
def change
5-
create_table :active_storage_db_files do |t|
5+
create_table :active_storage_db_files, id: primary_key_type do |t|
66
t.string :ref, null: false
77
t.binary :data, null: false
8-
t.datetime :created_at, null: false
8+
9+
if connection.supports_datetime_with_precision?
10+
t.datetime :created_at, precision: 6, null: false
11+
else
12+
t.datetime :created_at, null: false
13+
end
914

1015
t.index [:ref], unique: true
1116
end
1217
end
18+
19+
private
20+
21+
def primary_key_type
22+
config = Rails.configuration.generators
23+
primary_key_type = config.options[config.orm][:primary_key_type]
24+
primary_key_type || :primary_key
25+
end
1326
end

0 commit comments

Comments
 (0)