add uuid to active storage blob

pull/217/head
Pete Matsyburka 2 years ago
parent 652072d660
commit 5a3174a720

@ -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

@ -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|

Loading…
Cancel
Save