mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 10:31:50 +08:00
feat: add editor record migration
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- Added the required column `created_by` to the `snapshot_histories` table without a default value. This is not possible if the table is not empty.
|
||||||
|
- Added the required column `created_by` to the `updates` table without a default value. This is not possible if the table is not empty.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "snapshot_histories" ADD COLUMN "created_by" VARCHAR NOT NULL;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "snapshots" ADD COLUMN "created_by" VARCHAR,
|
||||||
|
ADD COLUMN "updated_by" VARCHAR;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "updates" ADD COLUMN "created_by" VARCHAR NOT NULL;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "snapshots" ADD CONSTRAINT "snapshots_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "snapshots" ADD CONSTRAINT "snapshots_updated_by_fkey" FOREIGN KEY ("updated_by") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "updates" ADD CONSTRAINT "updates_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "snapshot_histories" ADD CONSTRAINT "snapshot_histories_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
@@ -33,6 +33,10 @@ model User {
|
|||||||
aiSessions AiSession[]
|
aiSessions AiSession[]
|
||||||
updatedRuntimeConfigs RuntimeConfig[]
|
updatedRuntimeConfigs RuntimeConfig[]
|
||||||
userSnapshots UserSnapshot[]
|
userSnapshots UserSnapshot[]
|
||||||
|
createdSnapshot Snapshot[] @relation("createdSnapshot")
|
||||||
|
updatedSnapshot Snapshot[] @relation("updatedSnapshot")
|
||||||
|
createdUpdate Update[] @relation("createdUpdate")
|
||||||
|
createdHistory SnapshotHistory[] @relation("createdHistory")
|
||||||
|
|
||||||
@@index([email])
|
@@index([email])
|
||||||
@@map("users")
|
@@map("users")
|
||||||
@@ -241,9 +245,16 @@ model Snapshot {
|
|||||||
// the `updated_at` field will not record the time of record changed,
|
// the `updated_at` field will not record the time of record changed,
|
||||||
// but the created time of last seen update that has been merged into snapshot.
|
// but the created time of last seen update that has been merged into snapshot.
|
||||||
updatedAt DateTime @map("updated_at") @db.Timestamptz(3)
|
updatedAt DateTime @map("updated_at") @db.Timestamptz(3)
|
||||||
|
createdBy String? @map("created_by") @db.VarChar
|
||||||
|
updatedBy String? @map("updated_by") @db.VarChar
|
||||||
|
|
||||||
|
// should not delete origin snapshot even if user is deleted
|
||||||
|
// we only delete the snapshot if the workspace is deleted
|
||||||
|
createdByUser User? @relation(name: "createdSnapshot", fields: [createdBy], references: [id], onDelete: SetNull)
|
||||||
|
updatedByUser User? @relation(name: "updatedSnapshot", fields: [updatedBy], references: [id], onDelete: SetNull)
|
||||||
|
|
||||||
// @deprecated use updatedAt only
|
// @deprecated use updatedAt only
|
||||||
seq Int? @default(0) @db.Integer
|
seq Int? @default(0) @db.Integer
|
||||||
|
|
||||||
// we need to clear all hanging updates and snapshots before enable the foreign key on workspaceId
|
// we need to clear all hanging updates and snapshots before enable the foreign key on workspaceId
|
||||||
// workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
|
// workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
|
||||||
@@ -274,9 +285,13 @@ model Update {
|
|||||||
id String @map("guid") @db.VarChar
|
id String @map("guid") @db.VarChar
|
||||||
blob Bytes @db.ByteA
|
blob Bytes @db.ByteA
|
||||||
createdAt DateTime @map("created_at") @db.Timestamptz(3)
|
createdAt DateTime @map("created_at") @db.Timestamptz(3)
|
||||||
|
createdBy String @map("created_by") @db.VarChar
|
||||||
|
|
||||||
|
// delete update if createor's account is deleted
|
||||||
|
createdByUser User @relation(name: "createdUpdate", fields: [createdBy], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
// @deprecated use createdAt only
|
// @deprecated use createdAt only
|
||||||
seq Int? @db.Integer
|
seq Int? @db.Integer
|
||||||
|
|
||||||
@@id([workspaceId, id, createdAt])
|
@@id([workspaceId, id, createdAt])
|
||||||
@@map("updates")
|
@@map("updates")
|
||||||
@@ -289,6 +304,10 @@ model SnapshotHistory {
|
|||||||
blob Bytes @db.ByteA
|
blob Bytes @db.ByteA
|
||||||
state Bytes? @db.ByteA
|
state Bytes? @db.ByteA
|
||||||
expiredAt DateTime @map("expired_at") @db.Timestamptz(3)
|
expiredAt DateTime @map("expired_at") @db.Timestamptz(3)
|
||||||
|
createdBy String @map("created_by") @db.VarChar
|
||||||
|
|
||||||
|
// delete history if creator's account is deleted
|
||||||
|
createdByUser User @relation(name: "createdHistory", fields: [createdBy], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
@@id([workspaceId, id, timestamp])
|
@@id([workspaceId, id, timestamp])
|
||||||
@@map("snapshot_histories")
|
@@map("snapshot_histories")
|
||||||
|
|||||||
Reference in New Issue
Block a user