2024-04-16 18:19:34 -04:00
|
|
|
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
|
|
import { createId } from "@paralleldrive/cuid2";
|
2024-04-18 00:13:40 -04:00
|
|
|
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(),
|
|
|
|
});
|
|
|
|
|
2024-04-18 00:13:40 -04:00
|
|
|
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(),
|
2024-04-18 00:13:40 -04:00
|
|
|
type: text("type", { enum: ["react", "node"] }).notNull(),
|
2024-04-27 16:22:35 -04:00
|
|
|
visibility: text("visibility", { enum: ["public", "private"] }),
|
2024-04-16 18:19:34 -04:00
|
|
|
userId: text("user_id")
|
|
|
|
.notNull()
|
|
|
|
.references(() => user.id),
|
|
|
|
});
|
2024-04-18 00:13:40 -04:00
|
|
|
|
|
|
|
export type Sandbox = typeof sandbox.$inferSelect;
|
|
|
|
|
|
|
|
export const sandboxRelations = relations(sandbox, ({ one }) => ({
|
|
|
|
author: one(user, {
|
|
|
|
fields: [sandbox.userId],
|
|
|
|
references: [user.id],
|
|
|
|
}),
|
|
|
|
}));
|