initial commit

This commit is contained in:
Zoe
2026-01-11 05:04:29 -06:00
commit 0877cc10bd
65 changed files with 5009 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
import { relations } from "drizzle-orm";
import { pgTable, text, timestamp, boolean, index } from "drizzle-orm/pg-core";
export const user = pgTable("user", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").default(false).notNull(),
image: text("image"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at")
.defaultNow()
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
});
export const session = pgTable(
"session",
{
id: text("id").primaryKey(),
expiresAt: timestamp("expires_at").notNull(),
token: text("token").notNull().unique(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at")
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
ipAddress: text("ip_address"),
userAgent: text("user_agent"),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
},
(table) => [index("session_userId_idx").on(table.userId)],
);
export const account = pgTable(
"account",
{
id: text("id").primaryKey(),
accountId: text("account_id").notNull(),
providerId: text("provider_id").notNull(),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
accessToken: text("access_token"),
refreshToken: text("refresh_token"),
idToken: text("id_token"),
accessTokenExpiresAt: timestamp("access_token_expires_at"),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
scope: text("scope"),
password: text("password"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at")
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
},
(table) => [index("account_userId_idx").on(table.userId)],
);
export const verification = pgTable(
"verification",
{
id: text("id").primaryKey(),
identifier: text("identifier").notNull(),
value: text("value").notNull(),
expiresAt: timestamp("expires_at").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at")
.defaultNow()
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
},
(table) => [index("verification_identifier_idx").on(table.identifier)],
);
export const userRelations = relations(user, ({ many }) => ({
sessions: many(session),
accounts: many(account),
}));
export const sessionRelations = relations(session, ({ one }) => ({
user: one(user, {
fields: [session.userId],
references: [user.id],
}),
}));
export const accountRelations = relations(account, ({ one }) => ({
user: one(user, {
fields: [account.userId],
references: [user.id],
}),
}));
+7
View File
@@ -0,0 +1,7 @@
import { migrate } from "drizzle-orm/node-postgres/migrator";
import config from "~~/config/drizzle.config";
import { useDrizzle } from "~~/server/utils/drizzle";
const db = useDrizzle();
await migrate(db, { migrationsFolder: config.out! });
+43
View File
@@ -0,0 +1,43 @@
import { integer, pgTable, text, boolean, timestamp } from "drizzle-orm/pg-core";
import { uuidv7 } from "uuidv7";
import { user } from "./auth/auth.schema";
export * from "./auth/auth.schema";
export const agents = pgTable("agents", {
id: text("id").primaryKey().$defaultFn(() => 'agents_' + uuidv7()),
userId: text("user_id").references(() => user.id).notNull(),
name: text("name").notNull(),
systemPrompt: text("system_prompt").notNull(),
imageUrl: text("image_url")
});
export const topics = pgTable("topics", {
id: text("id").primaryKey().$defaultFn(() => 'topics_' + uuidv7()),
userId: text("user_id").references(() => user.id).notNull(),
agentId: text("agent_id").references(() => agents.id).notNull(),
name: text("name").notNull()
});
export const generations = pgTable("generations", {
id: text("id").primaryKey(),
userId: text("user_id").references(() => user.id).notNull(),
topicId: text("topic_id").references(() => topics.id).notNull(),
// nullable, because we insert into generations when we start a new generation,
// and once the generation is complete we insert the complete generation into messages
// but its currently needed to be able to fetch an entire message from its generation
// if necessary
messageId: text("message_id").references(() => messages.id),
createdAt: timestamp("created_at").notNull().defaultNow()
});
export const messages = pgTable("messages", {
id: text("id").primaryKey().$defaultFn(() => 'messages_' + uuidv7()),
userId: text("user_id").references(() => user.id).notNull(),
topicId: text("topic_id").references(() => topics.id).notNull(),
isUser: boolean("is_user").notNull(),
content: text("content").notNull(),
model: text("model"),
tokensGenerated: integer("tokens_generated"),
tokensUsedThinking: integer("tokens_used_thinking"),
createdAt: timestamp("created_at").notNull().defaultNow()
});