From b7d6237c2042261c7d5ac3b93b151b4d50bda5fa Mon Sep 17 00:00:00 2001 From: liuyi Date: Wed, 22 Nov 2023 03:31:22 +0000 Subject: [PATCH] feat(server): add doc history support (#4970) --- .../20231117062115_history/migration.sql | 14 ++++++++++ packages/backend/server/schema.prisma | 26 ++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 packages/backend/server/migrations/20231117062115_history/migration.sql diff --git a/packages/backend/server/migrations/20231117062115_history/migration.sql b/packages/backend/server/migrations/20231117062115_history/migration.sql new file mode 100644 index 0000000000..c432a65431 --- /dev/null +++ b/packages/backend/server/migrations/20231117062115_history/migration.sql @@ -0,0 +1,14 @@ +-- AlterTable +ALTER TABLE "blobs" ADD COLUMN "deleted_at" TIMESTAMPTZ(6); + +-- CreateTable +CREATE TABLE "snapshot_histories" ( + "workspace_id" VARCHAR(36) NOT NULL, + "guid" VARCHAR(36) NOT NULL, + "seq" INTEGER NOT NULL, + "blob" BYTEA NOT NULL, + "state" BYTEA, + "created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "snapshot_histories_pkey" PRIMARY KEY ("workspace_id","guid","seq") +); diff --git a/packages/backend/server/schema.prisma b/packages/backend/server/schema.prisma index 892810ca42..b8a78d3df4 100644 --- a/packages/backend/server/schema.prisma +++ b/packages/backend/server/schema.prisma @@ -164,12 +164,14 @@ model VerificationToken { } model Blob { - id Int @id @default(autoincrement()) @db.Integer - hash String @db.VarChar - workspaceId String @map("workspace_id") @db.VarChar - blob Bytes @db.ByteA + id Int @id @default(autoincrement()) @db.Integer + hash String @db.VarChar + workspaceId String @map("workspace_id") @db.VarChar + blob Bytes @db.ByteA length BigInt - createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6) + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6) + // not for keeping, but for snapshot history + deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6) @@unique([workspaceId, hash]) @@map("blobs") @@ -191,8 +193,8 @@ model OptimizedBlob { // the latest snapshot of each doc that we've seen // Snapshot + Updates are the latest state of the doc model Snapshot { - id String @default(uuid()) @map("guid") @db.VarChar workspaceId String @map("workspace_id") @db.VarChar + id String @default(uuid()) @map("guid") @db.VarChar blob Bytes @db.ByteA seq Int @default(0) @db.Integer state Bytes? @db.ByteA @@ -214,6 +216,18 @@ model Update { @@map("updates") } +model SnapshotHistory { + workspaceId String @map("workspace_id") @db.VarChar(36) + id String @map("guid") @db.VarChar(36) + seq Int @db.Integer + blob Bytes @db.ByteA + state Bytes? @db.ByteA + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6) + + @@id([workspaceId, id, seq]) + @@map("snapshot_histories") +} + model NewFeaturesWaitingList { id String @id @default(uuid()) @db.VarChar email String @unique