fix db relations + display sandboxes on dash

This commit is contained in:
Ishaan Dey
2024-04-18 00:13:40 -04:00
parent 14d76c605e
commit 19c2992824
13 changed files with 458 additions and 36 deletions

View File

@ -1,5 +1,6 @@
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { createId } from "@paralleldrive/cuid2";
import { relations } from "drizzle-orm";
export const user = sqliteTable("user", {
id: text("id")
@ -10,14 +11,30 @@ export const user = sqliteTable("user", {
email: text("email").notNull(),
});
export type User = typeof user.$inferSelect;
export const userRelations = relations(user, ({ many }) => ({
sandbox: many(sandbox),
}));
export const sandbox = sqliteTable("sandbox", {
id: text("id")
.$defaultFn(() => createId())
.primaryKey()
.unique(),
name: text("name").notNull(),
type: text("text", { enum: ["react", "node"] }).notNull(),
type: text("type", { enum: ["react", "node"] }).notNull(),
bucket: text("bucket"),
userId: text("user_id")
.notNull()
.references(() => user.id),
});
export type Sandbox = typeof sandbox.$inferSelect;
export const sandboxRelations = relations(sandbox, ({ one }) => ({
author: one(user, {
fields: [sandbox.userId],
references: [user.id],
}),
}));