Files
moreminimore-vibe/src/db/schema.ts
Olyno 237017acd9 feat: allow custom install and start commands (#892)
# Description

Gives the ability to define an `install` and `startup` command when
importing a project, so we can work on a project locally without any
issue.

# Preview

<img width="2256" height="1422" alt="image"
src="https://github.com/user-attachments/assets/2132b1cb-5f71-4b88-84db-8ecc81cf1f66"
/>

---------

Co-authored-by: Will Chen <willchen90@gmail.com>
2025-08-18 10:41:22 -07:00

162 lines
5.0 KiB
TypeScript

import { sql } from "drizzle-orm";
import { integer, sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
import { relations } from "drizzle-orm";
export const apps = sqliteTable("apps", {
id: integer("id").primaryKey({ autoIncrement: true }),
name: text("name").notNull(),
path: text("path").notNull(),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
updatedAt: integer("updated_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
githubOrg: text("github_org"),
githubRepo: text("github_repo"),
githubBranch: text("github_branch"),
supabaseProjectId: text("supabase_project_id"),
neonProjectId: text("neon_project_id"),
neonDevelopmentBranchId: text("neon_development_branch_id"),
neonPreviewBranchId: text("neon_preview_branch_id"),
vercelProjectId: text("vercel_project_id"),
vercelProjectName: text("vercel_project_name"),
vercelTeamId: text("vercel_team_id"),
vercelDeploymentUrl: text("vercel_deployment_url"),
installCommand: text("install_command"),
startCommand: text("start_command"),
chatContext: text("chat_context", { mode: "json" }),
});
export const chats = sqliteTable("chats", {
id: integer("id").primaryKey({ autoIncrement: true }),
appId: integer("app_id")
.notNull()
.references(() => apps.id, { onDelete: "cascade" }),
title: text("title"),
initialCommitHash: text("initial_commit_hash"),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
});
export const messages = sqliteTable("messages", {
id: integer("id").primaryKey({ autoIncrement: true }),
chatId: integer("chat_id")
.notNull()
.references(() => chats.id, { onDelete: "cascade" }),
role: text("role", { enum: ["user", "assistant"] }).notNull(),
content: text("content").notNull(),
approvalState: text("approval_state", {
enum: ["approved", "rejected"],
}),
commitHash: text("commit_hash"),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
});
export const versions = sqliteTable(
"versions",
{
id: integer("id").primaryKey({ autoIncrement: true }),
appId: integer("app_id")
.notNull()
.references(() => apps.id, { onDelete: "cascade" }),
commitHash: text("commit_hash").notNull(),
neonDbTimestamp: text("neon_db_timestamp"),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
updatedAt: integer("updated_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
},
(table) => [
// Unique constraint to prevent duplicate versions
unique("versions_app_commit_unique").on(table.appId, table.commitHash),
],
);
// Define relations
export const appsRelations = relations(apps, ({ many }) => ({
chats: many(chats),
versions: many(versions),
}));
export const chatsRelations = relations(chats, ({ many, one }) => ({
messages: many(messages),
app: one(apps, {
fields: [chats.appId],
references: [apps.id],
}),
}));
export const messagesRelations = relations(messages, ({ one }) => ({
chat: one(chats, {
fields: [messages.chatId],
references: [chats.id],
}),
}));
export const language_model_providers = sqliteTable(
"language_model_providers",
{
id: text("id").primaryKey(),
name: text("name").notNull(),
api_base_url: text("api_base_url").notNull(),
env_var_name: text("env_var_name"),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
updatedAt: integer("updated_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
},
);
export const language_models = sqliteTable("language_models", {
id: integer("id").primaryKey({ autoIncrement: true }),
displayName: text("display_name").notNull(),
apiName: text("api_name").notNull(),
builtinProviderId: text("builtin_provider_id"),
customProviderId: text("custom_provider_id").references(
() => language_model_providers.id,
{ onDelete: "cascade" },
),
description: text("description"),
max_output_tokens: integer("max_output_tokens"),
context_window: integer("context_window"),
createdAt: integer("created_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
updatedAt: integer("updated_at", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
});
// Define relations for new tables
export const languageModelProvidersRelations = relations(
language_model_providers,
({ many }) => ({
languageModels: many(language_models),
}),
);
export const languageModelsRelations = relations(
language_models,
({ one }) => ({
provider: one(language_model_providers, {
fields: [language_models.customProviderId],
references: [language_model_providers.id],
}),
}),
);
export const versionsRelations = relations(versions, ({ one }) => ({
app: one(apps, {
fields: [versions.appId],
references: [apps.id],
}),
}));