mirror of
https://github.com/khairul169/code-share.git
synced 2026-10-24 11:53:58 +07:00
feat: add project schema
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
export { user } from "./user";
|
||||
export { file } from "./file";
|
||||
export { project, projectRelations } from "./project";
|
||||
export { file, fileRelations } from "./file";
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
import { sql } from "drizzle-orm";
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import {
|
||||
integer,
|
||||
sqliteTable,
|
||||
text,
|
||||
foreignKey,
|
||||
index,
|
||||
} from "drizzle-orm/sqlite-core";
|
||||
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
|
||||
import { z } from "zod";
|
||||
import { user } from "./user";
|
||||
import { project } from "./project";
|
||||
|
||||
export const file = sqliteTable(
|
||||
"files",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
parentId: integer("parent_id"),
|
||||
userId: integer("user_id")
|
||||
projectId: integer("project_id")
|
||||
.notNull()
|
||||
.references(() => user.id),
|
||||
path: text("path").notNull().unique(),
|
||||
.references(() => project.id),
|
||||
parentId: integer("parent_id"),
|
||||
path: text("path").notNull(),
|
||||
filename: text("filename").notNull(),
|
||||
isDirectory: integer("is_directory", { mode: "boolean" })
|
||||
.notNull()
|
||||
@@ -38,9 +39,18 @@ export const file = sqliteTable(
|
||||
foreignColumns: [table.id],
|
||||
name: "parent_id_fk",
|
||||
}),
|
||||
pathIdx: index("file_path_idx").on(table.path),
|
||||
filenameIdx: index("file_name_idx").on(table.filename),
|
||||
})
|
||||
);
|
||||
|
||||
export const fileRelations = relations(file, ({ one }) => ({
|
||||
project: one(project, {
|
||||
fields: [file.projectId],
|
||||
references: [project.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const insertFileSchema = createInsertSchema(file);
|
||||
export const selectFileSchema = createSelectSchema(file);
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import { 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"),
|
||||
});
|
||||
|
||||
export const projectRelations = relations(project, ({ one, many }) => ({
|
||||
files: many(file),
|
||||
user: one(user, {
|
||||
fields: [project.userId],
|
||||
references: [user.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const insertProjectSchema = createInsertSchema(project);
|
||||
export const selectProjectSchema = createSelectSchema(project);
|
||||
|
||||
export type ProjectSchema = z.infer<typeof selectProjectSchema>;
|
||||
@@ -5,6 +5,7 @@ import { z } from "zod";
|
||||
|
||||
export const user = sqliteTable("users", {
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
email: text("email").notNull().unique(),
|
||||
password: text("password").notNull(),
|
||||
createdAt: text("created_at")
|
||||
|
||||
Reference in New Issue
Block a user