From 57740fa3faf23ed2871e086fcf09e648c65262eb Mon Sep 17 00:00:00 2001 From: AhmedFatthy1040 Date: Tue, 26 Nov 2024 22:47:51 +0200 Subject: [PATCH] refactor(schema): rename tables and columns to follow naming conventions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename tables: annotation → Annotations, image → Images, category → Categories, user → Users - Update column names to camelCase (e.g., image_id → imageId, created_at → createdAt) - Adjust foreign key constraints to follow new naming conventions --- .../20241126183518_init/migration.sql | 54 +++++++-------- prisma/schema.prisma | 66 +++++++++---------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/prisma/migrations/20241126183518_init/migration.sql b/prisma/migrations/20241126183518_init/migration.sql index d54fe3f..3905ef0 100644 --- a/prisma/migrations/20241126183518_init/migration.sql +++ b/prisma/migrations/20241126183518_init/migration.sql @@ -1,65 +1,65 @@ -- CreateTable -CREATE TABLE "annotation" ( +CREATE TABLE "Annotations" ( "id" SERIAL NOT NULL, - "image_id" INTEGER NOT NULL, + "imageId" INTEGER NOT NULL, "label" TEXT NOT NULL, - "x_min" DOUBLE PRECISION NOT NULL, - "y_min" DOUBLE PRECISION NOT NULL, - "x_max" DOUBLE PRECISION NOT NULL, - "y_max" DOUBLE PRECISION NOT NULL, - "is_ai_generated" BOOLEAN NOT NULL DEFAULT false, - "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "xMin" DOUBLE PRECISION NOT NULL, + "yMin" DOUBLE PRECISION NOT NULL, + "xMax" DOUBLE PRECISION NOT NULL, + "yMax" DOUBLE PRECISION NOT NULL, + "isAiGenerated" BOOLEAN NOT NULL DEFAULT false, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT "annotation_pkey" PRIMARY KEY ("id") + CONSTRAINT "Annotations_pkey" PRIMARY KEY ("id") ); -- CreateTable -CREATE TABLE "image" ( +CREATE TABLE "Images" ( "id" SERIAL NOT NULL, "filename" TEXT NOT NULL, "path" TEXT NOT NULL, - "category_id" INTEGER NOT NULL, - "user_id" INTEGER NOT NULL, - "uploaded_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "categoryId" INTEGER NOT NULL, + "userId" INTEGER NOT NULL, + "uploadedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT "image_pkey" PRIMARY KEY ("id") + CONSTRAINT "Images_pkey" PRIMARY KEY ("id") ); -- CreateTable -CREATE TABLE "category" ( +CREATE TABLE "Categories" ( "id" SERIAL NOT NULL, "name" TEXT NOT NULL, - "user_id" INTEGER NOT NULL, + "userId" INTEGER NOT NULL, - CONSTRAINT "category_pkey" PRIMARY KEY ("id") + CONSTRAINT "Categories_pkey" PRIMARY KEY ("id") ); -- CreateTable -CREATE TABLE "user" ( +CREATE TABLE "Users" ( "id" SERIAL NOT NULL, "username" TEXT NOT NULL, "email" TEXT NOT NULL, - "password_hash" TEXT NOT NULL, + "passwordHash" TEXT NOT NULL, "role" TEXT NOT NULL, - "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT "user_pkey" PRIMARY KEY ("id") + CONSTRAINT "Users_pkey" PRIMARY KEY ("id") ); -- CreateIndex -CREATE UNIQUE INDEX "user_username_key" ON "user"("username"); +CREATE UNIQUE INDEX "Users_username_key" ON "Users"("username"); -- CreateIndex -CREATE UNIQUE INDEX "user_email_key" ON "user"("email"); +CREATE UNIQUE INDEX "Users_email_key" ON "Users"("email"); -- AddForeignKey -ALTER TABLE "annotation" ADD CONSTRAINT "annotation_image_id_fkey" FOREIGN KEY ("image_id") REFERENCES "image"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "Annotations" ADD CONSTRAINT "Annotations_imageId_fkey" FOREIGN KEY ("imageId") REFERENCES "Images"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "image" ADD CONSTRAINT "image_category_id_fkey" FOREIGN KEY ("category_id") REFERENCES "category"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "Images" ADD CONSTRAINT "Images_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Categories"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "image" ADD CONSTRAINT "image_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "Images" ADD CONSTRAINT "Images_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "category" ADD CONSTRAINT "category_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "Categories" ADD CONSTRAINT "Categories_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ab77fde..8dac3be 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -13,46 +13,46 @@ datasource db { url = env("DATABASE_URL") } -model annotation { - id Int @id @default(autoincrement()) - image_id Int - label String - x_min Float - y_min Float - x_max Float - y_max Float - is_ai_generated Boolean @default(false) - created_at DateTime @default(now()) - image image @relation(fields: [image_id], references: [id]) +model Annotations { + id Int @id @default(autoincrement()) + imageId Int + label String + xMin Float + yMin Float + xMax Float + yMax Float + isAiGenerated Boolean @default(false) + createdAt DateTime @default(now()) + image Images @relation(fields: [imageId], references: [id]) } -model image { - id Int @id @default(autoincrement()) +model Images { + id Int @id @default(autoincrement()) filename String path String - category_id Int - user_id Int - uploaded_at DateTime @default(now()) - category category @relation(fields: [category_id], references: [id]) - user user @relation(fields: [user_id], references: [id]) - annotations annotation[] + categoryId Int + userId Int + uploadedAt DateTime @default(now()) + category Categories @relation(fields: [categoryId], references: [id]) + user Users @relation(fields: [userId], references: [id]) + annotations Annotations[] } -model category { - id Int @id @default(autoincrement()) - name String - user_id Int - user user @relation(fields: [user_id], references: [id]) - images image[] +model Categories { + id Int @id @default(autoincrement()) + name String + userId Int + user Users @relation(fields: [userId], references: [id]) + images Images[] } -model user { - id Int @id @default(autoincrement()) - username String @unique - email String @unique - password_hash String +model Users { + id Int @id @default(autoincrement()) + username String @unique + email String @unique + passwordHash String role String - created_at DateTime @default(now()) - images image[] - categories category[] + createdAt DateTime @default(now()) + images Images[] + categories Categories[] } \ No newline at end of file