add uuid to active storage blob
This commit is contained in:
@@ -19,6 +19,16 @@ ActiveSupport.on_load(:active_storage_attachment) do
|
||||
end
|
||||
|
||||
ActiveSupport.on_load(:active_storage_blob) do
|
||||
attribute :uuid, :string, default: -> { SecureRandom.uuid }
|
||||
|
||||
def uuid
|
||||
super || begin
|
||||
new_uuid = SecureRandom.uuid
|
||||
update_columns(uuid: new_uuid)
|
||||
new_uuid
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
service.delete(key)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddUuidToActiveStorageBlobs < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :active_storage_blobs, :uuid, :string
|
||||
|
||||
add_index :active_storage_blobs, :uuid, unique: true
|
||||
end
|
||||
end
|
||||
+3
-1
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_02_03_113455) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_02_18_082157) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
@@ -74,7 +74,9 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_03_113455) do
|
||||
t.bigint "byte_size", null: false
|
||||
t.string "checksum"
|
||||
t.datetime "created_at", null: false
|
||||
t.string "uuid"
|
||||
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
|
||||
t.index ["uuid"], name: "index_active_storage_blobs_on_uuid", unique: true
|
||||
end
|
||||
|
||||
create_table "active_storage_variant_records", force: :cascade do |t|
|
||||
|
||||
Reference in New Issue
Block a user