about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app/models/blog.rb2
-rw-r--r--config/environments/production.rb3
-rw-r--r--db/migrate/20231014194459_create_active_storage_tables.active_storage.rb57
-rw-r--r--db/schema.rb32
4 files changed, 93 insertions, 1 deletions
diff --git a/app/models/blog.rb b/app/models/blog.rb index e43990e..362f69f 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb
@@ -11,6 +11,8 @@ class Blog < ApplicationRecord
11 validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published 11 validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published
12 validates :user, presence: true 12 validates :user, presence: true
13 13
14 has_many_attached :images
15
14 before_validation :set_draft_title 16 before_validation :set_draft_title
15 before_save :set_published_at 17 before_save :set_published_at
16 18
diff --git a/config/environments/production.rb b/config/environments/production.rb index e814a66..ccd3012 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb
@@ -92,4 +92,7 @@ Rails.application.configure do
92 92
93 # Do not dump schema after migrations. 93 # Do not dump schema after migrations.
94 config.active_record.dump_schema_after_migration = false 94 config.active_record.dump_schema_after_migration = false
95
96 # Store uploaded files on the local file system (see config/storage.yml for options).
97 config.active_storage.service = :local
95end 98end
diff --git a/db/migrate/20231014194459_create_active_storage_tables.active_storage.rb b/db/migrate/20231014194459_create_active_storage_tables.active_storage.rb new file mode 100644 index 0000000..8a7bfe1 --- /dev/null +++ b/db/migrate/20231014194459_create_active_storage_tables.active_storage.rb
@@ -0,0 +1,57 @@
1# This migration comes from active_storage (originally 20170806125915)
2class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
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
57end
diff --git a/db/schema.rb b/db/schema.rb index 49c7925..edbb24e 100644 --- a/db/schema.rb +++ b/db/schema.rb
@@ -10,7 +10,35 @@
10# 10#
11# It's strongly recommended that you check this file into your version control system. 11# It's strongly recommended that you check this file into your version control system.
12 12
13ActiveRecord::Schema[7.0].define(version: 2023_10_14_141657) do 13ActiveRecord::Schema[7.0].define(version: 2023_10_14_194459) do
14 create_table "active_storage_attachments", force: :cascade do |t|
15 t.string "name", null: false
16 t.string "record_type", null: false
17 t.bigint "record_id", null: false
18 t.bigint "blob_id", null: false
19 t.datetime "created_at", null: false
20 t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
21 t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
22 end
23
24 create_table "active_storage_blobs", force: :cascade do |t|
25 t.string "key", null: false
26 t.string "filename", null: false
27 t.string "content_type"
28 t.text "metadata"
29 t.string "service_name", null: false
30 t.bigint "byte_size", null: false
31 t.string "checksum"
32 t.datetime "created_at", null: false
33 t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
34 end
35
36 create_table "active_storage_variant_records", force: :cascade do |t|
37 t.bigint "blob_id", null: false
38 t.string "variation_digest", null: false
39 t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
40 end
41
14 create_table "audits", force: :cascade do |t| 42 create_table "audits", force: :cascade do |t|
15 t.integer "auditable_id" 43 t.integer "auditable_id"
16 t.string "auditable_type" 44 t.string "auditable_type"
@@ -362,6 +390,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_14_141657) do
362 t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true 390 t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
363 end 391 end
364 392
393 add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
394 add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
365 add_foreign_key "blogs", "users" 395 add_foreign_key "blogs", "users"
366 add_foreign_key "comments", "blogs" 396 add_foreign_key "comments", "blogs"
367 add_foreign_key "comments", "comments", column: "reply_to_id" 397 add_foreign_key "comments", "comments", column: "reply_to_id"