Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Warnings:

- A unique constraint covering the columns `[primaryBusinessId]` on the table `users` will be added. If there are existing duplicate values, this will fail.

*/
-- CreateEnum
CREATE TYPE "public"."BusinessStatus" AS ENUM ('ACTIVE', 'INACTIVE', 'PENDING_VERIFICATION', 'SUSPENDED');

-- AlterTable
ALTER TABLE "public"."Booking" ADD COLUMN "businessId" INTEGER;

-- AlterTable
ALTER TABLE "public"."users" ADD COLUMN "primaryBusinessId" INTEGER;

-- CreateTable
CREATE TABLE "public"."Service" (
"id" SERIAL NOT NULL,
"businessId" INTEGER NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
"price" INTEGER,
"duration" INTEGER,
"imageUrl" TEXT,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"category" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Service_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."Business" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"lineUserId" TEXT,
"smsPhoneNumber" TEXT,
"emailAddress" TEXT,
"businessPhone" TEXT,
"businessEmail" TEXT,
"lineVerified" BOOLEAN NOT NULL DEFAULT false,
"smsVerified" BOOLEAN NOT NULL DEFAULT false,
"emailVerified" BOOLEAN NOT NULL DEFAULT false,
"notifyViaLine" BOOLEAN NOT NULL DEFAULT true,
"notifyViaSms" BOOLEAN NOT NULL DEFAULT false,
"notifyViaEmail" BOOLEAN NOT NULL DEFAULT true,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"status" "public"."BusinessStatus" NOT NULL DEFAULT 'ACTIVE',

CONSTRAINT "Business_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "Service_businessId_idx" ON "public"."Service"("businessId");

-- CreateIndex
CREATE UNIQUE INDEX "Service_businessId_name_key" ON "public"."Service"("businessId", "name");

-- CreateIndex
CREATE UNIQUE INDEX "Business_slug_key" ON "public"."Business"("slug");

-- CreateIndex
CREATE INDEX "Business_lineUserId_idx" ON "public"."Business"("lineUserId");

-- CreateIndex
CREATE UNIQUE INDEX "users_primaryBusinessId_key" ON "public"."users"("primaryBusinessId");

-- AddForeignKey
ALTER TABLE "public"."Service" ADD CONSTRAINT "Service_businessId_fkey" FOREIGN KEY ("businessId") REFERENCES "public"."Business"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."users" ADD CONSTRAINT "users_primaryBusinessId_fkey" FOREIGN KEY ("primaryBusinessId") REFERENCES "public"."Business"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "public"."Booking" ADD CONSTRAINT "Booking_businessId_fkey" FOREIGN KEY ("businessId") REFERENCES "public"."Business"("id") ON DELETE SET NULL ON UPDATE CASCADE;
76 changes: 76 additions & 0 deletions packages/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,74 @@ model TravelSchedule {
@@index([endDate])
}

//OKBOOMER: custom table for business services menu
model Service {
id Int @id @default(autoincrement())
businessId Int
business Business @relation(fields: [businessId], references: [id])

name String // "Haircut", "Coloring + Treatment"
description String?
price Int? // 800
duration Int? // minutes, e.g. 60
imageUrl String? // hosted photo (upload to your server or Cloudinary)
isActive Boolean @default(true)
category String? // "Hair", "Nails", "Massage"
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@unique([businessId, name]) // unique name per business
@@index([businessId])
}

//OKBOOMER: custom table for business linkage
enum BusinessStatus {
ACTIVE
INACTIVE
PENDING_VERIFICATION
SUSPENDED
}

model Business {
id Int @id @default(autoincrement())
name String // e.g. "Salon XYZ"
slug String @unique // e.g. "salon-xyz" — stable identifier for LIFF ?business=...
lineUserId String? // Uxxxxxxxx...
smsPhoneNumber String? // optional phone for sms
emailAddress String? // optional notify email
businessPhone String? // Public customer contact (displayed in confirmations, etc.)
businessEmail String? // Public customer email (displayed in confirmations, etc.)

// Verification
lineVerified Boolean @default(false)
smsVerified Boolean @default(false)
emailVerified Boolean @default(false)

// Notification
notifyViaLine Boolean @default(true)
notifyViaSms Boolean @default(false)
notifyViaEmail Boolean @default(true)

// Time stamps
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Status (Active/Inactive/Pending/Suspended)
status BusinessStatus @default(ACTIVE)

// Admin who can manage this business (one-to-many)
primaryAdmin User?
//secondaryAdmin User?

// Bookings tagged with this business
bookings Booking[] @relation("BusinessBookings")

// Services offered (one-to-many)
services Service[]

@@index([lineUserId])
}

// It holds Personal Profiles of a User plus it has email, password and other core things..
model User {
id Int @id @default(autoincrement())
Expand Down Expand Up @@ -486,6 +554,10 @@ model User {
agents Agent[]
holidaySettings UserHolidaySettings?

//OKBOOMER: business linkage
primaryBusinessId Int? @unique
primaryBusiness Business? @relation(fields: [primaryBusinessId], references: [id])

autoOptInFeatures Boolean @default(false)

@@unique([email])
Expand Down Expand Up @@ -899,6 +971,10 @@ model Booking {
expenseLogs CreditExpenseLog[]
report BookingReport?

//OKBOOMER: business linkage
businessId Int?
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: New Booking.businessId foreign key is missing an explicit index, risking slower business-based lookups/joins and FK maintenance scans on PostgreSQL.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/prisma/schema.prisma, line 975:

<comment>New `Booking.businessId` foreign key is missing an explicit index, risking slower business-based lookups/joins and FK maintenance scans on PostgreSQL.</comment>

<file context>
@@ -899,6 +971,10 @@ model Booking {
   report                       BookingReport?
 
+  //OKBOOMER: business linkage
+  businessId Int?
+  business   Business? @relation("BusinessBookings", fields: [businessId], references: [id])
+
</file context>
Fix with Cubic

business Business? @relation("BusinessBookings", fields: [businessId], references: [id])

// @@partial_index([reassignById])

@@index([eventTypeId])
Expand Down
Loading