mirror of
https://github.com/khairul169/code-share.git
synced 2026-10-24 11:53:58 +07:00
feat: add personal project list, add project settings, etc
This commit is contained in:
+61
-15
@@ -1,22 +1,48 @@
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
||||
import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
||||
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
|
||||
import { z } from "zod";
|
||||
import { user } from "./user";
|
||||
import { file } from "./file";
|
||||
|
||||
export const project = sqliteTable("projects", {
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
userId: integer("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id),
|
||||
slug: text("slug").notNull().unique(),
|
||||
title: text("title").notNull(),
|
||||
createdAt: text("created_at")
|
||||
.notNull()
|
||||
.default(sql`CURRENT_TIMESTAMP`),
|
||||
deletedAt: text("deleted_at"),
|
||||
});
|
||||
const defaultSettings: ProjectSettingsSchema = {
|
||||
css: {
|
||||
preprocessor: null,
|
||||
tailwindcss: false,
|
||||
},
|
||||
js: {
|
||||
transpiler: null,
|
||||
packages: [],
|
||||
},
|
||||
};
|
||||
|
||||
export const project = sqliteTable(
|
||||
"projects",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
userId: integer("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id),
|
||||
slug: text("slug").notNull().unique(),
|
||||
title: text("title").notNull(),
|
||||
|
||||
visibility: text("visibility", {
|
||||
enum: ["public", "private", "unlisted"],
|
||||
}).default("private"),
|
||||
|
||||
settings: text("settings", { mode: "json" })
|
||||
.$type<Partial<ProjectSettingsSchema>>()
|
||||
.default(defaultSettings),
|
||||
|
||||
createdAt: text("created_at")
|
||||
.notNull()
|
||||
.default(sql`CURRENT_TIMESTAMP`),
|
||||
deletedAt: text("deleted_at"),
|
||||
},
|
||||
(table) => ({
|
||||
visibilityEnum: index("project_visibility_idx").on(table.visibility),
|
||||
})
|
||||
);
|
||||
|
||||
export const projectRelations = relations(project, ({ one, many }) => ({
|
||||
files: many(file),
|
||||
@@ -26,7 +52,27 @@ export const projectRelations = relations(project, ({ one, many }) => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
export const insertProjectSchema = createInsertSchema(project);
|
||||
export const selectProjectSchema = createSelectSchema(project);
|
||||
export const projectSettingsSchema = z.object({
|
||||
css: z.object({
|
||||
preprocessor: z.enum(["", "postcss"]).optional().nullable(),
|
||||
tailwindcss: z.boolean().optional().nullable(),
|
||||
}),
|
||||
|
||||
js: z.object({
|
||||
transpiler: z.enum(["", "swc"]).optional().nullable(),
|
||||
packages: z
|
||||
.object({ name: z.string().min(1), url: z.string().min(1).url() })
|
||||
.array(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type ProjectSettingsSchema = z.infer<typeof projectSettingsSchema>;
|
||||
|
||||
export const insertProjectSchema = createInsertSchema(project, {
|
||||
settings: projectSettingsSchema,
|
||||
});
|
||||
export const selectProjectSchema = createSelectSchema(project, {
|
||||
settings: projectSettingsSchema.partial(),
|
||||
});
|
||||
|
||||
export type ProjectSchema = z.infer<typeof selectProjectSchema>;
|
||||
|
||||
Reference in New Issue
Block a user