Skip to content

Commit

Permalink
refactor(schema): rename tables and columns to follow naming conventions
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
AhmedFatthy1040 committed Nov 26, 2024
1 parent f22acaa commit 57740fa
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 60 deletions.
54 changes: 27 additions & 27 deletions prisma/migrations/20241126183518_init/migration.sql
Original file line number Diff line number Diff line change
@@ -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;
66 changes: 33 additions & 33 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}

0 comments on commit 57740fa

Please sign in to comment.