UNPKG

exclaim-recovery-database

Version:

Shared database schemas for Exclaim Recovery platform

121 lines (113 loc) 5.67 kB
import { pgTable, index, text, jsonb, timestamp, vector, integer, uuid, boolean } from "drizzle-orm/pg-core" import { sql } from "drizzle-orm" export const document = pgTable("Document", { id: text().primaryKey().notNull(), content: text().notNull(), metadata: jsonb(), createdAt: timestamp({ precision: 3, mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(), vector: vector({ dimensions: 1536 }).notNull(), }, (table) => [ index("document_vector_idx").using("hnsw", table.vector.asc().nullsLast().op("vector_cosine_ops")), ]); export const userDocument = pgTable("UserDocument", { id: text().primaryKey().notNull(), userId: text().notNull(), documentId: text().notNull(), createdAt: timestamp({ precision: 3, mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(), metadata: jsonb(), vector: vector({ dimensions: 1536 }).notNull(), }, (table) => [ index("UserDocument_userId_idx").using("btree", table.userId.asc().nullsLast().op("text_ops")), index("user_document_userId_idx").using("btree", table.userId.asc().nullsLast().op("text_ops")), index("user_document_vector_idx").using("hnsw", table.vector.asc().nullsLast().op("vector_cosine_ops")), ]); export const smartRecoveryDocument = pgTable("SMARTRecoveryDocument", { id: text().primaryKey().notNull(), content: text().notNull(), metadata: jsonb(), createdAt: timestamp({ precision: 3, mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(), vector: vector({ dimensions: 1536 }).notNull(), }, (table) => [ index("smart_recovery_vector_idx").using("hnsw", table.vector.asc().nullsLast().op("vector_cosine_ops")), index("smartrecoverydocument_vector_idx").using("hnsw", table.vector.asc().nullsLast().op("vector_cosine_ops")), ]); export const scientificStudyDocument = pgTable("ScientificStudyDocument", { id: text().primaryKey().notNull(), title: text(), abstract: text(), content: text().notNull(), authors: text().array(), publicationYear: integer(), journal: text(), doi: text(), metadata: jsonb(), createdAt: timestamp({ precision: 3, mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(), vector: vector({ dimensions: 1536 }).notNull(), }, (table) => [ index("scientific_study_vector_idx").using("hnsw", table.vector.asc().nullsLast().op("vector_cosine_ops")), index("scientificstudydocument_vector_idx").using("hnsw", table.vector.asc().nullsLast().op("vector_cosine_ops")), ]); export const gaStepDocument = pgTable("GAStepDocument", { id: uuid().defaultRandom().primaryKey().notNull(), stepNumber: integer().notNull(), title: text().notNull(), description: text().notNull(), detailedContent: text().notNull(), reflectionPrompts: text().array(), commonChallenges: text().array(), milestoneNames: text().array(), metadata: jsonb(), createdAt: timestamp({ mode: 'string' }).default(sql`CURRENT_TIMESTAMP`), updatedAt: timestamp({ mode: 'string' }).default(sql`CURRENT_TIMESTAMP`), vector: vector({ dimensions: 1536 }), }, (table) => [ index("ga_step_number_idx").using("btree", table.stepNumber.asc().nullsLast().op("int4_ops")), index("ga_step_vector_idx").using("hnsw", table.vector.asc().nullsLast().op("vector_cosine_ops")), ]); export const gaResourceDocument = pgTable("GAResourceDocument", { id: uuid().defaultRandom().primaryKey().notNull(), stepNumber: integer(), title: text().notNull(), type: text().notNull(), url: text(), content: text(), metadata: jsonb(), createdAt: timestamp({ mode: 'string' }).default(sql`CURRENT_TIMESTAMP`), vector: vector({ dimensions: 1536 }), }, (table) => [ index("ga_resource_step_idx").using("btree", table.stepNumber.asc().nullsLast().op("int4_ops")), index("ga_resource_type_idx").using("btree", table.type.asc().nullsLast().op("text_ops")), index("ga_resource_vector_idx").using("hnsw", table.vector.asc().nullsLast().op("vector_cosine_ops")), ]); export const gaReflectionDocument = pgTable("GAReflectionDocument", { id: uuid().defaultRandom().primaryKey().notNull(), userId: text().notNull(), stepNumber: integer().notNull(), content: text().notNull(), isPrivate: boolean().default(false), tags: text().array(), createdAt: timestamp({ mode: 'string' }).default(sql`CURRENT_TIMESTAMP`), updatedAt: timestamp({ mode: 'string' }).default(sql`CURRENT_TIMESTAMP`), vector: vector({ dimensions: 1536 }), }, (table) => [ index("ga_reflection_step_idx").using("btree", table.stepNumber.asc().nullsLast().op("int4_ops")), index("ga_reflection_user_idx").using("btree", table.userId.asc().nullsLast().op("text_ops")), index("ga_reflection_vector_idx").using("hnsw", table.vector.asc().nullsLast().op("vector_cosine_ops")), ]); export const blogDocument = pgTable("BlogDocument", { id: uuid().defaultRandom().primaryKey().notNull(), title: text().notNull(), content: text().notNull(), authorId: text().notNull(), published: boolean().default(false), tags: text().array(), coverImage: text(), createdAt: timestamp({ mode: 'string' }).default(sql`CURRENT_TIMESTAMP`), updatedAt: timestamp({ mode: 'string' }).default(sql`CURRENT_TIMESTAMP`), metadata: jsonb(), vector: vector({ dimensions: 1536 }), }, (table) => [ index("blog_author_idx").using("btree", table.authorId.asc().nullsLast().op("text_ops")), index("blog_published_idx").using("btree", table.published.asc().nullsLast().op("bool_ops")), index("blog_vector_idx").using("hnsw", table.vector.asc().nullsLast().op("vector_cosine_ops")), ]);