mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
✨ feat(database): added user memory persona schema (#11833)
This commit is contained in:
@@ -1471,6 +1471,57 @@ table user_memories_preferences {
|
||||
}
|
||||
}
|
||||
|
||||
table user_memory_persona_document_histories {
|
||||
id varchar(255) [pk, not null]
|
||||
user_id text
|
||||
persona_id varchar(255)
|
||||
profile varchar(255) [not null, default: 'default']
|
||||
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" [not null, default: `now()`]
|
||||
accessed_at "timestamp with time zone" [not null, default: `now()`]
|
||||
created_at "timestamp with time zone" [not null, default: `now()`]
|
||||
updated_at "timestamp with time zone" [not null, default: `now()`]
|
||||
|
||||
indexes {
|
||||
persona_id [name: 'user_persona_document_histories_persona_id_index']
|
||||
user_id [name: 'user_persona_document_histories_user_id_index']
|
||||
profile [name: 'user_persona_document_histories_profile_index']
|
||||
}
|
||||
}
|
||||
|
||||
table user_memory_persona_documents {
|
||||
id varchar(255) [pk, not null]
|
||||
user_id text
|
||||
profile varchar(255) [not null, default: 'default']
|
||||
tagline text
|
||||
persona text
|
||||
memory_ids jsonb
|
||||
source_ids jsonb
|
||||
metadata jsonb
|
||||
version integer [not null, default: 1]
|
||||
captured_at "timestamp with time zone" [not null, default: `now()`]
|
||||
accessed_at "timestamp with time zone" [not null, default: `now()`]
|
||||
created_at "timestamp with time zone" [not null, default: `now()`]
|
||||
updated_at "timestamp with time zone" [not null, default: `now()`]
|
||||
|
||||
indexes {
|
||||
(user_id, profile) [name: 'user_persona_documents_user_id_profile_unique', unique]
|
||||
user_id [name: 'user_persona_documents_user_id_index']
|
||||
}
|
||||
}
|
||||
|
||||
ref: accounts.user_id > users.id
|
||||
|
||||
ref: passkey.userId > users.id
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
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");
|
||||
11957
packages/database/migrations/meta/0075_snapshot.json
Normal file
11957
packages/database/migrations/meta/0075_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -525,7 +525,14 @@
|
||||
"when": 1769341100106,
|
||||
"tag": "0074_add_fk_indexes_for_cascade_delete",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 75,
|
||||
"version": "7",
|
||||
"when": 1769362978088,
|
||||
"tag": "0075_add_user_memory_persona",
|
||||
"breakpoints": true
|
||||
}
|
||||
],
|
||||
"version": "6"
|
||||
}
|
||||
}
|
||||
81
packages/database/src/schemas/userMemories/persona.ts
Normal file
81
packages/database/src/schemas/userMemories/persona.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
||||
import { index, integer, jsonb, pgTable, text, uniqueIndex } from 'drizzle-orm/pg-core';
|
||||
|
||||
import { createNanoId } from '../../utils/idGenerator';
|
||||
import { timestamps, timestamptz, varchar255 } from '../_helpers';
|
||||
import { users } from '../user';
|
||||
|
||||
export const userPersonaDocuments = pgTable(
|
||||
'user_memory_persona_documents',
|
||||
{
|
||||
id: varchar255('id')
|
||||
.$defaultFn(() => createNanoId(18)())
|
||||
.primaryKey(),
|
||||
|
||||
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }),
|
||||
profile: varchar255('profile').default('default').notNull(),
|
||||
|
||||
tagline: text('tagline'),
|
||||
persona: text('persona'),
|
||||
|
||||
memoryIds: jsonb('memory_ids').$type<string[]>(),
|
||||
sourceIds: jsonb('source_ids').$type<string[]>(),
|
||||
metadata: jsonb('metadata').$type<Record<string, unknown>>(),
|
||||
|
||||
version: integer('version').notNull().default(1),
|
||||
capturedAt: timestamptz('captured_at').notNull().defaultNow(),
|
||||
|
||||
...timestamps,
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex('user_persona_documents_user_id_profile_unique').on(table.userId, table.profile),
|
||||
index('user_persona_documents_user_id_index').on(table.userId),
|
||||
],
|
||||
);
|
||||
|
||||
export const userPersonaDocumentHistories = pgTable(
|
||||
'user_memory_persona_document_histories',
|
||||
{
|
||||
id: varchar255('id')
|
||||
.$defaultFn(() => createNanoId(18)())
|
||||
.primaryKey(),
|
||||
|
||||
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }),
|
||||
personaId: varchar255('persona_id').references(() => userPersonaDocuments.id, {
|
||||
onDelete: 'cascade',
|
||||
}),
|
||||
profile: varchar255('profile').default('default').notNull(),
|
||||
|
||||
snapshotPersona: text('snapshot_persona'),
|
||||
snapshotTagline: text('snapshot_tagline'),
|
||||
reasoning: text('reasoning'),
|
||||
diffPersona: text('diff_persona'),
|
||||
diffTagline: text('diff_tagline'),
|
||||
snapshot: text('snapshot'),
|
||||
summary: text('summary'),
|
||||
editedBy: varchar255('edited_by').default('agent'),
|
||||
|
||||
memoryIds: jsonb('memory_ids').$type<string[]>(),
|
||||
sourceIds: jsonb('source_ids').$type<string[]>(),
|
||||
metadata: jsonb('metadata').$type<Record<string, unknown>>(),
|
||||
|
||||
previousVersion: integer('previous_version'),
|
||||
nextVersion: integer('next_version'),
|
||||
|
||||
capturedAt: timestamptz('captured_at').notNull().defaultNow(),
|
||||
|
||||
...timestamps,
|
||||
},
|
||||
(table) => [
|
||||
index('user_persona_document_histories_persona_id_index').on(table.personaId),
|
||||
index('user_persona_document_histories_user_id_index').on(table.userId),
|
||||
index('user_persona_document_histories_profile_index').on(table.profile),
|
||||
],
|
||||
);
|
||||
|
||||
export type UserPersonaDocument = typeof userPersonaDocuments.$inferSelect;
|
||||
export type NewUserPersonaDocument = typeof userPersonaDocuments.$inferInsert;
|
||||
|
||||
export type UserPersonaDocumentHistoriesItem = typeof userPersonaDocumentHistories.$inferSelect;
|
||||
export type NewUserPersonaDocumentHistoriesItem =
|
||||
typeof userPersonaDocumentHistories.$inferInsert;
|
||||
Reference in New Issue
Block a user