mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 09:16:55 +00:00
feat(asset): decouple logical assets from physical storage with StorageKey and implement O(1) copy
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `key` on the `assets` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "assets" DROP COLUMN "key",
|
||||
ADD COLUMN "storage_key_id" TEXT;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "storage_keys" (
|
||||
"id" TEXT NOT NULL,
|
||||
"key" TEXT NOT NULL,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "storage_keys_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "storage_keys_key_key" ON "storage_keys"("key");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "assets" ADD CONSTRAINT "assets_storage_key_id_fkey" FOREIGN KEY ("storage_key_id") REFERENCES "storage_keys"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
+13
-1
@@ -347,7 +347,6 @@ model Asset {
|
||||
id String @id @default(ulid())
|
||||
name String @default("")
|
||||
nameNgram String[] @default([]) @map("name_ngram")
|
||||
key String?
|
||||
type AssetType
|
||||
mediaType String? @map("media_type")
|
||||
fileCount Int @default(0) @map("file_count")
|
||||
@@ -370,6 +369,9 @@ model Asset {
|
||||
target Asset? @relation("SymlinkTarget", fields: [targetId], references: [id])
|
||||
symlinks Asset[] @relation("SymlinkTarget")
|
||||
|
||||
storageKeyId String? @map("storage_key_id")
|
||||
storageKey StorageKey? @relation(fields: [storageKeyId], references: [id])
|
||||
|
||||
metadataValues AssetMetadataValue[] @relation("AssetToMetadataValues")
|
||||
|
||||
creatorId String? @map("creator_id")
|
||||
@@ -403,6 +405,16 @@ model Asset {
|
||||
@@unique([parentId, targetId], name: "parentIdTargetId")
|
||||
}
|
||||
|
||||
model StorageKey {
|
||||
id String @id @default(ulid())
|
||||
key String @unique
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
assets Asset[]
|
||||
|
||||
@@map("storage_keys")
|
||||
}
|
||||
|
||||
model AssetMetadataValue {
|
||||
id String @id @default(ulid())
|
||||
assetId String @map("asset_id")
|
||||
|
||||
Reference in New Issue
Block a user