diff --git a/apps/backend/src/app/db/schema.ts b/apps/backend/src/app/db/schema.ts new file mode 100644 index 0000000..a80d34b --- /dev/null +++ b/apps/backend/src/app/db/schema.ts @@ -0,0 +1,91 @@ +import { pgTable } from "drizzle-orm/pg-core"; +import * as p from "drizzle-orm/pg-core"; +import { createInsertSchema, createSelectSchema } from "drizzle-zod"; + +export const UsersTable = pgTable("users", { + // Unique identifier on a technical aspect. + uuid: p.uuid("uuid").unique().primaryKey().defaultRandom().notNull(), + + firstName: p + .varchar("first_name", { + length: 24, + }) + .notNull(), + + lastName: p + .varchar("last_name", { + length: 24, + }) + .notNull(), + + //hash (Argonid2 hash) + hash: p + .varchar("hash", { + length: 97, + }) + .notNull(), + + //METADATA + iat: p + .timestamp("issued_at", { + withTimezone: true, + }) + .defaultNow() + .notNull(), + + gdprAcceptance: p + .timestamp("ack_gdpr", { + withTimezone: true, + }) + .defaultNow() + .notNull(), + + isAdmin: p.boolean("is_admin").default(false).notNull(), +}); +export const UsersTableSelectSchema = createSelectSchema(UsersTable); +export const UsersTableInsertSchema = createInsertSchema(UsersTable); + +export const FilesTable = pgTable("files", { + // Unique identifier on a technical aspect. + uuid: p.uuid("uuid").unique().primaryKey().defaultRandom().notNull(), + + fileName: p + .varchar("file_name", { + length: 128, + }) + .notNull(), + + fileSize: p + .integer("file_size") + .notNull(), + + //TODO Replace by file type reference + fileType: p + .varchar("file_type", { + length: 50, + }) + .notNull(), + + isRestricted: p + .boolean("is_restricted") + .default(false) + .notNull(), + + uploadedAt: p + .timestamp("uploaded_at", { + withTimezone: true, + }) + .defaultNow() + .notNull(), + + uploadedBy: p + .varchar("uploaded_by", { + length: 64, + }) + .notNull(), +}) + +//TODO Many/Many Files -> Categories + +//TODO Files types +