add uuid to active storage blob

This commit is contained in:
Pete Matsyburka
2024-02-18 10:24:43 +02:00
parent 652072d660
commit 5a3174a720
3 changed files with 22 additions and 1 deletions
+10
View File
@@ -19,6 +19,16 @@ ActiveSupport.on_load(:active_storage_attachment) do
end end
ActiveSupport.on_load(:active_storage_blob) do 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 def delete
service.delete(key) service.delete(key)
end 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
View File
@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" 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.bigint "byte_size", null: false
t.string "checksum" t.string "checksum"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.string "uuid"
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true 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 end
create_table "active_storage_variant_records", force: :cascade do |t| create_table "active_storage_variant_records", force: :cascade do |t|