42 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-04-16 18:19:34 -04:00
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { createId } from "@paralleldrive/cuid2";
import { relations } from "drizzle-orm";
2024-04-16 18:19:34 -04:00
export const user = sqliteTable("user", {
id: text("id")
.$defaultFn(() => createId())
.primaryKey()
.unique(),
name: text("name").notNull(),
email: text("email").notNull(),
});
export type User = typeof user.$inferSelect;
export const userRelations = relations(user, ({ many }) => ({
sandbox: many(sandbox),
}));
2024-04-16 18:19:34 -04:00
export const sandbox = sqliteTable("sandbox", {
id: text("id")
.$defaultFn(() => createId())
.primaryKey()
.unique(),
name: text("name").notNull(),
type: text("type", { enum: ["react", "node"] }).notNull(),
bucket: text("bucket"),
2024-04-21 22:55:49 -04:00
init: integer("init", { mode: "boolean" }).default(false),
2024-04-16 18:19:34 -04:00
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],
}),
}));