Files
cjyyzx/packages/database/migrations/0075_add_user_memory_persona.sql
T
xiaohei 428644e286
Revalidate Docs / Revalidate Docs (push) Failing after 2s
E2E CI / Check Duplicate Run (push) Failing after 5s
Test CI / Check Duplicate Run (push) Failing after 6s
E2E CI / Test Web App (push) Has been skipped
Test CI / Test Packages (push) Has been skipped
Test CI / Test App (shard 1/3) (push) Has been skipped
Test CI / Test App (shard 2/3) (push) Has been skipped
Test CI / Test App (shard 3/3) (push) Has been skipped
Test CI / Test Desktop App (push) Has been skipped
🔄 Branch Synchronization / sync-branches (push) Failing after 11s
Test CI / Test Database (push) Has been skipped
Test CI / Merge and Upload App Coverage (push) Has been skipped
Database Schema Visualization CI / build (push) Failing after 4m14s
Enterprise AI Workspace prototype: LobeChat (de-branded) + Enterprise Gateway + Postgres/Redis stack
2026-04-21 12:58:00 +08:00

52 lines
3.4 KiB
SQL

CREATE TABLE IF NOT EXISTS "user_memory_persona_document_histories" (
"id" varchar(255) PRIMARY KEY NOT NULL,
"user_id" text,
"persona_id" varchar(255),
"profile" varchar(255) DEFAULT 'default' NOT NULL,
"snapshot_persona" text,
"snapshot_tagline" text,
"reasoning" text,
"diff_persona" text,
"diff_tagline" text,
"snapshot" text,
"summary" text,
"edited_by" varchar(255) DEFAULT 'agent',
"memory_ids" jsonb,
"source_ids" jsonb,
"metadata" jsonb,
"previous_version" integer,
"next_version" integer,
"captured_at" timestamp with time zone DEFAULT now() NOT NULL,
"accessed_at" timestamp with time zone DEFAULT now() NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "user_memory_persona_documents" (
"id" varchar(255) PRIMARY KEY NOT NULL,
"user_id" text,
"profile" varchar(255) DEFAULT 'default' NOT NULL,
"tagline" text,
"persona" text,
"memory_ids" jsonb,
"source_ids" jsonb,
"metadata" jsonb,
"version" integer DEFAULT 1 NOT NULL,
"captured_at" timestamp with time zone DEFAULT now() NOT NULL,
"accessed_at" timestamp with time zone DEFAULT now() NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "user_memory_persona_document_histories" DROP CONSTRAINT IF EXISTS "user_memory_persona_document_histories_user_id_users_id_fk";--> statement-breakpoint
ALTER TABLE "user_memory_persona_document_histories" ADD CONSTRAINT "user_memory_persona_document_histories_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_memory_persona_document_histories" DROP CONSTRAINT IF EXISTS "user_memory_persona_document_histories_persona_id_user_memory_persona_documents_id_fk";--> statement-breakpoint
ALTER TABLE "user_memory_persona_document_histories" ADD CONSTRAINT "user_memory_persona_document_histories_persona_id_user_memory_persona_documents_id_fk" FOREIGN KEY ("persona_id") REFERENCES "public"."user_memory_persona_documents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "user_persona_document_histories_persona_id_index" ON "user_memory_persona_document_histories" USING btree ("persona_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "user_persona_document_histories_user_id_index" ON "user_memory_persona_document_histories" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "user_persona_document_histories_profile_index" ON "user_memory_persona_document_histories" USING btree ("profile");--> statement-breakpoint
ALTER TABLE "user_memory_persona_documents" DROP CONSTRAINT IF EXISTS "user_memory_persona_documents_user_id_users_id_fk";--> statement-breakpoint
ALTER TABLE "user_memory_persona_documents" ADD CONSTRAINT "user_memory_persona_documents_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "user_persona_documents_user_id_profile_unique" ON "user_memory_persona_documents" USING btree ("user_id","profile");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "user_persona_documents_user_id_index" ON "user_memory_persona_documents" USING btree ("user_id");