Skip to content

Commit 5eeeaf2

Browse files
committed
initialize ActiveStorage
1 parent c8601c4 commit 5eeeaf2

File tree

5 files changed

+94
-7
lines changed

5 files changed

+94
-7
lines changed

config/application.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class Application < Rails::Application
5656
config.action_mailer.preview_paths << Rails.root.join('spec/mailers/previews')
5757

5858
# Specify default options for Rails generators
59-
config.generators do |g|
60-
g.orm :active_record, primary_key_type: :uuid
61-
end
59+
# config.generators do |g|
60+
# g.orm :active_record, primary_key_type: :uuid
61+
# end
6262

6363
# Allow tables in addition to existing default tags
6464
config.action_view.sanitized_allowed_tags = ActionView::Base.sanitized_allowed_tags + %w[table thead tbody tfoot td tr details summary]

db/cable_schema.rb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# This migration comes from active_storage (originally 20170806125915)
2+
class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
3+
def change
4+
# Use Active Record's configured type for primary and foreign keys
5+
primary_key_type, foreign_key_type = primary_and_foreign_key_types
6+
7+
create_table :active_storage_blobs, id: primary_key_type do |t|
8+
t.string :key, null: false
9+
t.string :filename, null: false
10+
t.string :content_type
11+
t.text :metadata
12+
t.string :service_name, null: false
13+
t.bigint :byte_size, null: false
14+
t.string :checksum
15+
16+
if connection.supports_datetime_with_precision?
17+
t.datetime :created_at, precision: 6, null: false
18+
else
19+
t.datetime :created_at, null: false
20+
end
21+
22+
t.index [ :key ], unique: true
23+
end
24+
25+
create_table :active_storage_attachments, id: primary_key_type do |t|
26+
t.string :name, null: false
27+
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
28+
t.references :blob, null: false, type: foreign_key_type
29+
30+
if connection.supports_datetime_with_precision?
31+
t.datetime :created_at, precision: 6, null: false
32+
else
33+
t.datetime :created_at, null: false
34+
end
35+
36+
t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true
37+
t.foreign_key :active_storage_blobs, column: :blob_id
38+
end
39+
40+
create_table :active_storage_variant_records, id: primary_key_type do |t|
41+
t.belongs_to :blob, null: false, index: false, type: foreign_key_type
42+
t.string :variation_digest, null: false
43+
44+
t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
45+
t.foreign_key :active_storage_blobs, column: :blob_id
46+
end
47+
end
48+
49+
private
50+
def primary_and_foreign_key_types
51+
config = Rails.configuration.generators
52+
setting = config.options[config.orm][:primary_key_type]
53+
primary_key_type = setting || :primary_key
54+
foreign_key_type = setting || :bigint
55+
[ primary_key_type, foreign_key_type ]
56+
end
57+
end

db/queue_schema.rb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/schema.rb

Lines changed: 32 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)