mirror of
https://github.com/khairul169/code-share.git
synced 2025-04-29 00:59:37 +07:00
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { sql } from "drizzle-orm";
|
|
import {
|
|
integer,
|
|
sqliteTable,
|
|
text,
|
|
foreignKey,
|
|
} from "drizzle-orm/sqlite-core";
|
|
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
|
|
import { z } from "zod";
|
|
import { user } from "./user";
|
|
|
|
export const file = sqliteTable(
|
|
"files",
|
|
{
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
parentId: integer("parent_id"),
|
|
userId: integer("user_id")
|
|
.notNull()
|
|
.references(() => user.id),
|
|
path: text("path").notNull().unique(),
|
|
filename: text("filename").notNull(),
|
|
isDirectory: integer("is_directory", { mode: "boolean" })
|
|
.notNull()
|
|
.default(false),
|
|
isFile: integer("is_file", { mode: "boolean" }).notNull().default(false),
|
|
isPinned: integer("is_pinned", { mode: "boolean" })
|
|
.notNull()
|
|
.default(false),
|
|
content: text("content"),
|
|
createdAt: text("created_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
deletedAt: text("deleted_at"),
|
|
},
|
|
(table) => ({
|
|
parentFk: foreignKey({
|
|
columns: [table.parentId],
|
|
foreignColumns: [table.id],
|
|
name: "parent_id_fk",
|
|
}),
|
|
})
|
|
);
|
|
|
|
export const insertFileSchema = createInsertSchema(file);
|
|
export const selectFileSchema = createSelectSchema(file);
|
|
|
|
export type FileSchema = z.infer<typeof selectFileSchema>;
|