From be121ef7ca1f27a49c2b63358ca9ad03484906d7 Mon Sep 17 00:00:00 2001 From: Mathis Date: Mon, 2 Sep 2024 14:58:04 +0200 Subject: [PATCH] Enable new schema for file types and machines Removed the deprecated `firstName` and `lastName` fields and introduced `email` and `uploader` fields. Added `FilesTypesTable`, `MachinesTable`, and `FilesTypeForMachine` for managing file types and machine associations. Updated the `fileType` field to reference `FilesTypesTable`. --- apps/backend/src/app/db/schema.ts | 70 +++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/apps/backend/src/app/db/schema.ts b/apps/backend/src/app/db/schema.ts index 562cc4f..8adc553 100644 --- a/apps/backend/src/app/db/schema.ts +++ b/apps/backend/src/app/db/schema.ts @@ -6,7 +6,7 @@ export const UsersTable = pgTable("users", { // Unique identifier on a technical aspect. uuid: p.uuid("uuid").unique().primaryKey().defaultRandom().notNull(), - firstName: p + /*firstName: p .varchar("first_name", { length: 24, }) @@ -16,6 +16,12 @@ export const UsersTable = pgTable("users", { .varchar("last_name", { length: 24, }) + .notNull(),**/ + + email: p + .varchar("email", { + length: 64, + }) .notNull(), //hash (Argonid2 hash) @@ -55,14 +61,20 @@ export const FilesTable = pgTable("files", { }) .notNull(), + uploader: p + .varchar("uploader", { + length: 64, + }) + .default("anonyme") + .notNull(), + fileSize: p.integer("file_size").notNull(), //TODO Replace by file type reference fileType: p - .varchar("file_type", { - length: 50, - }) - .notNull(), + .uuid("file_type") + .notNull() + .references(() => FilesTypesTable.id), isRestricted: p.boolean("is_restricted").default(false).notNull(), @@ -80,6 +92,50 @@ export const FilesTable = pgTable("files", { .notNull(), }); -//TODO Many/Many Files -> Categories - //TODO Files types +export const FilesTypesTable = pgTable("f_types", { + //uuid + id: p.uuid("id").unique().primaryKey().defaultRandom().notNull(), + + typeName: p + .varchar("type_name", { + length: 64, + }) + .notNull(), + + mime: p + .varchar("mime_type", { + length: 64, + }) + .unique() + .notNull(), +}); + +export const MachinesTable = pgTable("machines", { + id: p.uuid("id").unique().primaryKey().defaultRandom().notNull(), + + machineName: p + .varchar("machine_name", { + length: 64, + }) + .notNull(), + + machineType: p + .varchar("machine_type", { + length: 64, + }) + .notNull(), + + //supported files format +}); + +export const FilesTypeForMachine = pgTable("f_type_for_machines", { + machineId: p + .uuid("machine_id") + .notNull() + .references(() => MachinesTable.id), + fileTypeId: p + .uuid("file_type_id") + .notNull() + .references(() => FilesTypesTable.id), +});