Merge branch 'master' into feature/cases

This commit is contained in:
2026-07-10 15:26:36 +03:30
68 changed files with 2497 additions and 604 deletions

View File

@@ -0,0 +1,25 @@
-- AlterTable
ALTER TABLE "users" ADD COLUMN "mobile" TEXT;
-- CreateIndex
CREATE UNIQUE INDEX "users_mobile_key" ON "users"("mobile");
-- CreateTable
CREATE TABLE "phone_verification_codes" (
"id" TEXT NOT NULL,
"userId" TEXT,
"mobile" TEXT NOT NULL,
"codeHash" TEXT NOT NULL,
"purpose" TEXT NOT NULL,
"expiresAt" TIMESTAMP(3) NOT NULL,
"verifiedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "phone_verification_codes_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "phone_verification_codes_mobile_purpose_createdAt_idx" ON "phone_verification_codes"("mobile", "purpose", "createdAt");
-- AddForeignKey
ALTER TABLE "phone_verification_codes" ADD CONSTRAINT "phone_verification_codes_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,11 @@
-- Enforce one treatment detail per lab case (1:1 via join table).
-- Keep the earliest-linked detail when duplicate rows exist for the same case.
DELETE FROM "lab_case_details" lcd
WHERE lcd.ctid NOT IN (
SELECT MIN(inner_lcd.ctid)
FROM "lab_case_details" inner_lcd
GROUP BY inner_lcd."labCaseId"
);
CREATE UNIQUE INDEX "lab_case_details_labCaseId_key" ON "lab_case_details"("labCaseId");

View File

@@ -11,6 +11,7 @@ datasource db {
model User {
id String @id @default(uuid())
email String @unique
mobile String? @unique
passwordHash String?
googleId String? @unique
facebookId String? @unique
@@ -26,6 +27,7 @@ model User {
statusChangedLabCaseTasks LabCaseTask[] @relation("LabCaseTaskLastStatusChangedBy")
labCaseTaskStatusEvents LabCaseTaskStatusEvent[]
labCaseComments LabCaseComment[]
phoneVerificationCodes PhoneVerificationCode[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -33,6 +35,22 @@ model User {
@@map("users")
}
model PhoneVerificationCode {
id String @id @default(uuid())
userId String?
mobile String
codeHash String
purpose String
expiresAt DateTime
verifiedAt DateTime?
createdAt DateTime @default(now())
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([mobile, purpose, createdAt])
@@map("phone_verification_codes")
}
model OrganizationType {
id String @id @default(uuid())
name String @unique // "CLINIC" or "LAB"
@@ -222,7 +240,7 @@ model LabCaseAttachment {
}
model LabCaseDetail {
labCaseId String
labCaseId String @unique
treatmentDetailId String @unique
labCase LabCase @relation(fields: [labCaseId], references: [id], onDelete: Cascade)

View File

@@ -12,16 +12,15 @@ import {
buildProsthesisStepCodes,
} from './catalog-seed-data';
// Load environment variables from the correct path
const envPath = path.join(__dirname, '..', '.env');
console.log('Loading .env from:', envPath);
config({ path: envPath });
// Load .env when running locally; Docker injects DATABASE_URL via env_file.
if (!process.env.DATABASE_URL) {
const envPath = path.join(__dirname, '..', '.env');
console.log('Loading .env from:', envPath);
config({ path: envPath });
}
// Verify DATABASE_URL is loaded
if (!process.env.DATABASE_URL) {
console.error('❌ DATABASE_URL is not set in environment');
console.log('Current directory:', process.cwd());
console.log('.env path:', envPath);
process.exit(1);
}