Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
355f21b
Passwords also refuse a distinctive word of an institute's name, not …
omerFixesBugs Nov 16, 2026
7016eff
Sprint 1 P1-J plan (docs/plans/sprint-1-p1j-password-hash.md): the ap…
omerFixesBugs Nov 16, 2026
25da8a3
Sprint 1 P2 plan (docs/plans/sprint-1-p2-files.md): institute profile…
omerFixesBugs Nov 16, 2026
995e61e
Test users get phone numbers no other test user of the same database …
omerFixesBugs Nov 16, 2026
356c448
The app login can no longer read users.password_hash (P1-J): SELECT o…
omerFixesBugs Nov 16, 2026
3ca69eb
Every Prisma client leaves users.password_hash out of its reads (P1-J…
omerFixesBugs Nov 16, 2026
30e85f6
Files and the institute profile in the database (P2 task 1): stored_f…
omerFixesBugs Nov 16, 2026
687a83b
CORS_ORIGINS is normalised in env.ts as browsers send Origin (lower-c…
omerFixesBugs Nov 16, 2026
ff8981c
Shared file caps, types and the institute profile schema (P2 task 2):…
omerFixesBugs Nov 16, 2026
917d5eb
The start-up login check also refuses a login with REPLICATION (a rep…
omerFixesBugs Nov 16, 2026
bc6644b
Password login without the hash (P1-J): the API hashes the typed pass…
omerFixesBugs Nov 16, 2026
b0e6315
GET /me/password reads hasPassword from auth_my_password_is_set() (P1…
omerFixesBugs Nov 16, 2026
47fb357
Docs for P1-J: database.md (password_hash not readable by the app, a …
omerFixesBugs Nov 16, 2026
20b29e9
Redis is pinned to one exact version, redis:7.4.11-alpine (the versio…
omerFixesBugs Nov 16, 2026
81bfc26
Docs for the follow-ups: decisions-pending gets the section "Small fo…
omerFixesBugs Nov 16, 2026
9cc9d54
Image processing for uploads (P2 task 3): sharp 0.35.5 (already in th…
omerFixesBugs Nov 16, 2026
b0e010b
FileStore and the per-institute cap (P2 task 4): PostgresFileStore is…
omerFixesBugs Nov 16, 2026
caec9f7
Photo and profile routes (P2 task 5): GET/PUT/DELETE /students/:id/ph…
omerFixesBugs Nov 16, 2026
57cf79f
Web (P2 task 6): Settings → Institute profile (names, EIIN, contact, …
omerFixesBugs Nov 16, 2026
4e4cbb2
Docs for P2 (task 7): docs/files.md, database.md (the three tables an…
omerFixesBugs Nov 16, 2026
724ffb0
The photo dialog's preview URL is made when a file is chosen, not in …
omerFixesBugs Nov 16, 2026
110857d
files.spec: the profile fields by id ("নাম (বাংলা)" is also part of t…
omerFixesBugs Nov 16, 2026
8c3a4f9
After the review (P1-J7): a dedicated login for the password login. j…
omerFixesBugs Nov 16, 2026
72b714b
The password login looks the hash up on its own database login (Login…
omerFixesBugs Nov 16, 2026
06f3236
Docs after the P1-J review: what an injection in an ordinary request …
omerFixesBugs Nov 16, 2026
82f6600
Test phones never wrap and their lock survives races (review of PR #1…
omerFixesBugs Nov 16, 2026
27403c3
The institute-name rule compares passwords and names like the phone r…
omerFixesBugs Nov 16, 2026
7aa31c5
An origin setting with a login, a path, a query or a fragment is no o…
omerFixesBugs Nov 16, 2026
fd6430e
Docs after the review of PR #17: P1-I's title line says it is built h…
omerFixesBugs Nov 16, 2026
9dbee45
P1-J migration after the second review: it first checks that jantrik_…
omerFixesBugs Nov 16, 2026
a980a60
The password login's database login must reach the same database, por…
omerFixesBugs Nov 16, 2026
ff673b8
Docs after the second P1-J review: the server upgrade creates the rol…
omerFixesBugs Nov 16, 2026
13deed2
A file reference is tied to its kind (review R6): UNIQUE (tenant_id, …
omerFixesBugs Nov 16, 2026
cb86722
Uploads hold no database connection while they arrive (review R1): th…
omerFixesBugs Nov 16, 2026
459bcf7
Web after the review: a chosen image is shrunk in the browser to 1600…
omerFixesBugs Nov 16, 2026
944e840
Docs after the review: auth.md (the request pipeline and @OwnTransact…
omerFixesBugs Nov 16, 2026
282c8b6
Review round 2, API: uploads in flight bounded before multer (16 per …
omerFixesBugs Nov 16, 2026
cfd4506
Review round 2, web: the browser asks for the EXIF orientation explic…
omerFixesBugs Nov 16, 2026
73eb83b
Docs for review round 2: auth.md (the upload routes' re-checks, Uploa…
omerFixesBugs Nov 16, 2026
e622e52
The interceptor opens its transaction through an unchecked entry (aro…
omerFixesBugs Nov 16, 2026
3d2c5d5
Review round 3: no upload slot leaks when the client left before Uplo…
omerFixesBugs Nov 16, 2026
de19108
The two new origin tests' development settings also name DATABASE_LOG…
omerFixesBugs Nov 16, 2026
aa0105b
Merge P1-J (#16) into the small follow-ups (#17): the ready resolutio…
omerFixesBugs Nov 16, 2026
b1efceb
Merge remote-tracking branch 'origin/feature/sprint-1-p1j-password-ha…
omerFixesBugs Nov 16, 2026
b5d3697
Merge remote-tracking branch 'origin/feature/sprint-1-p2-files' into …
omerFixesBugs Nov 16, 2026
c857102
Merge remote-tracking branch 'origin/feature/small-followups-after-p1…
omerFixesBugs Nov 16, 2026
9309fa8
Work in progress: a staff guide draft and draft legal texts (terms of…
omerFixesBugs Nov 19, 2026
ed5d56c
Docs only: a plain staff guide draft (signing in, setup, students, gu…
omerFixesBugs Nov 19, 2026
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
Prev Previous commit
Next Next commit
A file reference is tied to its kind (review R6): UNIQUE (tenant_id, …
…id, kind) on stored_files and a fixed kind column in each foreign key (students.photo_file_kind always STUDENT_PHOTO; the profile's logo, signature and seal kinds), so a photo column can only hold a photo; the database tests name the rule that refuses each write (R10)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
omerFixesBugs and claude committed Nov 16, 2026
commit 13deed23539dc5497b55ec325dfc842d05fa7909
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ CREATE TABLE "institute_profiles" (
"logo_file_id" UUID,
"head_signature_file_id" UUID,
"seal_file_id" UUID,
"logo_file_kind" "stored_file_kind" NOT NULL DEFAULT 'LOGO',
"head_signature_file_kind" "stored_file_kind" NOT NULL DEFAULT 'SIGNATURE',
"seal_file_kind" "stored_file_kind" NOT NULL DEFAULT 'SEAL',
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

Expand All @@ -66,6 +69,9 @@ CREATE INDEX "stored_files_tenant_id_kind_idx" ON "stored_files"("tenant_id", "k
-- CreateIndex
CREATE UNIQUE INDEX "stored_files_tenant_id_id_key" ON "stored_files"("tenant_id", "id");

-- CreateIndex (what the kind-bound foreign keys point at)
CREATE UNIQUE INDEX "stored_files_tenant_id_id_kind_key" ON "stored_files"("tenant_id", "id", "kind");

-- CreateIndex
CREATE UNIQUE INDEX "stored_file_usage_tenant_id_key" ON "stored_file_usage"("tenant_id");

Expand All @@ -79,13 +85,13 @@ CREATE UNIQUE INDEX "institute_profiles_tenant_id_key" ON "institute_profiles"("
CREATE UNIQUE INDEX "institute_profiles_tenant_id_id_key" ON "institute_profiles"("tenant_id", "id");

-- CreateIndex
CREATE UNIQUE INDEX "institute_profiles_tenant_id_logo_file_id_key" ON "institute_profiles"("tenant_id", "logo_file_id");
CREATE UNIQUE INDEX "institute_profiles_tenant_id_logo_file_id_logo_file_kind_key" ON "institute_profiles"("tenant_id", "logo_file_id", "logo_file_kind");

-- CreateIndex
CREATE UNIQUE INDEX "institute_profiles_tenant_id_head_signature_file_id_key" ON "institute_profiles"("tenant_id", "head_signature_file_id");
CREATE UNIQUE INDEX "institute_profiles_tenant_id_head_signature_file_id_head_si_key" ON "institute_profiles"("tenant_id", "head_signature_file_id", "head_signature_file_kind");

-- CreateIndex
CREATE UNIQUE INDEX "institute_profiles_tenant_id_seal_file_id_key" ON "institute_profiles"("tenant_id", "seal_file_id");
CREATE UNIQUE INDEX "institute_profiles_tenant_id_seal_file_id_seal_file_kind_key" ON "institute_profiles"("tenant_id", "seal_file_id", "seal_file_kind");

-- AddForeignKey
ALTER TABLE "stored_files" ADD CONSTRAINT "stored_files_tenant_id_fkey" FOREIGN KEY ("tenant_id") REFERENCES "tenants"("id") ON DELETE RESTRICT ON UPDATE RESTRICT;
Expand All @@ -100,13 +106,13 @@ ALTER TABLE "stored_file_usage" ADD CONSTRAINT "stored_file_usage_tenant_id_fkey
ALTER TABLE "institute_profiles" ADD CONSTRAINT "institute_profiles_tenant_id_fkey" FOREIGN KEY ("tenant_id") REFERENCES "tenants"("id") ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE "institute_profiles" ADD CONSTRAINT "institute_profiles_tenant_id_logo_file_id_fkey" FOREIGN KEY ("tenant_id", "logo_file_id") REFERENCES "stored_files"("tenant_id", "id") ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE "institute_profiles" ADD CONSTRAINT "institute_profiles_tenant_id_logo_file_id_logo_file_kind_fkey" FOREIGN KEY ("tenant_id", "logo_file_id", "logo_file_kind") REFERENCES "stored_files"("tenant_id", "id", "kind") ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE "institute_profiles" ADD CONSTRAINT "institute_profiles_tenant_id_head_signature_file_id_fkey" FOREIGN KEY ("tenant_id", "head_signature_file_id") REFERENCES "stored_files"("tenant_id", "id") ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE "institute_profiles" ADD CONSTRAINT "institute_profiles_tenant_id_head_signature_file_id_head_s_fkey" FOREIGN KEY ("tenant_id", "head_signature_file_id", "head_signature_file_kind") REFERENCES "stored_files"("tenant_id", "id", "kind") ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE "institute_profiles" ADD CONSTRAINT "institute_profiles_tenant_id_seal_file_id_fkey" FOREIGN KEY ("tenant_id", "seal_file_id") REFERENCES "stored_files"("tenant_id", "id") ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE "institute_profiles" ADD CONSTRAINT "institute_profiles_tenant_id_seal_file_id_seal_file_kind_fkey" FOREIGN KEY ("tenant_id", "seal_file_id", "seal_file_kind") REFERENCES "stored_files"("tenant_id", "id", "kind") ON DELETE RESTRICT ON UPDATE RESTRICT;

-- Row-Level Security (docs/database.md → Checklist).
ALTER TABLE stored_files ENABLE ROW LEVEL SECURITY;
Expand Down Expand Up @@ -182,6 +188,11 @@ ALTER TABLE institute_profiles
ADD CONSTRAINT institute_profiles_established_year CHECK (
established_year IS NULL OR established_year BETWEEN 1800 AND 2100
),
-- Each image column's kind is fixed; with the kind in each foreign key, a logo can only be a LOGO
-- file, the signature a SIGNATURE, the seal a SEAL (so never a student's photo).
ADD CONSTRAINT institute_profiles_file_kinds CHECK (
logo_file_kind = 'LOGO' AND head_signature_file_kind = 'SIGNATURE' AND seal_file_kind = 'SEAL'
),
-- One file in one place: the unique indexes cover each column; this covers the row's three.
ADD CONSTRAINT institute_profiles_distinct_files CHECK (
(logo_file_id IS NULL OR (logo_file_id IS DISTINCT FROM head_signature_file_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
-- Sprint 1 P2: a student's photo is a stored file (kind STUDENT_PHOTO), referenced by a composite
-- key so it can only be a file of the student's own institute. The old photo_url column was never
-- written (always null) and goes.
-- Sprint 1 P2: a student's photo is a stored file of kind STUDENT_PHOTO, referenced by a composite
-- key with the kind (fixed by a CHECK), so it can only be a photo of the student's own institute.
-- The old photo_url column was never written (always null) and goes.

-- AlterTable
ALTER TABLE "students" DROP COLUMN "photo_url",
ADD COLUMN "photo_file_id" UUID;
ADD COLUMN "photo_file_id" UUID,
ADD COLUMN "photo_file_kind" "stored_file_kind" NOT NULL DEFAULT 'STUDENT_PHOTO';

ALTER TABLE students
ADD CONSTRAINT students_photo_file_kind CHECK (photo_file_kind = 'STUDENT_PHOTO');

-- CreateIndex (also the foreign key's index: a file belongs to one student)
CREATE UNIQUE INDEX "students_tenant_id_photo_file_id_key" ON "students"("tenant_id", "photo_file_id");
CREATE UNIQUE INDEX "students_tenant_id_photo_file_id_photo_file_kind_key" ON "students"("tenant_id", "photo_file_id", "photo_file_kind");

-- AddForeignKey
ALTER TABLE "students" ADD CONSTRAINT "students_tenant_id_photo_file_id_fkey" FOREIGN KEY ("tenant_id", "photo_file_id") REFERENCES "stored_files"("tenant_id", "id") ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE "students" ADD CONSTRAINT "students_tenant_id_photo_file_id_photo_file_kind_fkey" FOREIGN KEY ("tenant_id", "photo_file_id", "photo_file_kind") REFERENCES "stored_files"("tenant_id", "id", "kind") ON DELETE RESTRICT ON UPDATE RESTRICT;
99 changes: 54 additions & 45 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1002,36 +1002,38 @@ model Membership {
}

model Student {
id String @id @default(uuid(7)) @db.Uuid
tenantId String @map("tenant_id") @db.Uuid
studentCode String @map("student_code")
userId String? @map("user_id") @db.Uuid
nameBn String? @map("name_bn")
nameEn String? @map("name_en")
dateOfBirth DateTime? @map("date_of_birth") @db.Date
id String @id @default(uuid(7)) @db.Uuid
tenantId String @map("tenant_id") @db.Uuid
studentCode String @map("student_code")
userId String? @map("user_id") @db.Uuid
nameBn String? @map("name_bn")
nameEn String? @map("name_en")
dateOfBirth DateTime? @map("date_of_birth") @db.Date
gender Gender?
/// The student's photo (stored_files, kind STUDENT_PHOTO); replaced files are deleted.
photoFileId String? @map("photo_file_id") @db.Uuid
status StudentStatus @default(ACTIVE)
photoFileId String? @map("photo_file_id") @db.Uuid
/// Always STUDENT_PHOTO (CHECK): part of the foreign key, so the photo can only be a photo.
photoFileKind StoredFileKind @default(STUDENT_PHOTO) @map("photo_file_kind")
status StudentStatus @default(ACTIVE)
// Fields required for Bangladesh education board registration.
fatherNameBn String? @map("father_name_bn")
fatherNameEn String? @map("father_name_en")
motherNameBn String? @map("mother_name_bn")
motherNameEn String? @map("mother_name_en")
fatherNameBn String? @map("father_name_bn")
fatherNameEn String? @map("father_name_en")
motherNameBn String? @map("mother_name_bn")
motherNameEn String? @map("mother_name_en")
religion Religion?
/// 17-digit birth registration number; unique per tenant when present.
birthRegistrationNo String? @map("birth_registration_no")
bloodGroup BloodGroup? @map("blood_group")
presentAddress String? @map("present_address")
permanentAddress String? @map("permanent_address")
birthRegistrationNo String? @map("birth_registration_no")
bloodGroup BloodGroup? @map("blood_group")
presentAddress String? @map("present_address")
permanentAddress String? @map("permanent_address")
/// Soft delete. Queries must filter `deletedAt: null` themselves.
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(3)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(3)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)

tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Restrict)
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
photoFile StoredFile? @relation("StudentPhoto", fields: [tenantId, photoFileId], references: [tenantId, id], onDelete: Restrict, onUpdate: Restrict)
photoFile StoredFile? @relation("StudentPhoto", fields: [tenantId, photoFileId, photoFileKind], references: [tenantId, id, kind], onDelete: Restrict, onUpdate: Restrict)
guardians StudentGuardian[]
enrolments Enrolment[]

Expand All @@ -1051,7 +1053,7 @@ model Student {
@@unique([tenantId, studentCode])
@@unique([tenantId, birthRegistrationNo])
// A file belongs to one student (also the foreign key's index).
@@unique([tenantId, photoFileId])
@@unique([tenantId, photoFileId, photoFileKind])
@@index([tenantId, status], where: raw("deleted_at IS NULL"))
@@index([tenantId, nameEn])
// Trigram indexes for ILIKE '%…%' search (GET /students).
Expand Down Expand Up @@ -3165,6 +3167,8 @@ model StoredFile {
profileSeal InstituteProfile? @relation("InstituteProfileSeal")

@@unique([tenantId, id])
// What the kind-bound foreign keys point at.
@@unique([tenantId, id, kind])
@@index([tenantId, kind])
@@map("stored_files")
}
Expand All @@ -3188,39 +3192,44 @@ model StoredFileUsage {
/// The institute's own profile (at most one per institute, created on the first save or image).
/// tenants.name stays the name the platform registered; these are the institute's own words.
model InstituteProfile {
id String @id @default(uuid(7)) @db.Uuid
tenantId String @unique @map("tenant_id") @db.Uuid
nameBn String? @map("name_bn")
nameEn String? @map("name_en")
shortName String? @map("short_name")
id String @id @default(uuid(7)) @db.Uuid
tenantId String @unique @map("tenant_id") @db.Uuid
nameBn String? @map("name_bn")
nameEn String? @map("name_en")
shortName String? @map("short_name")
/// BANBEIS EIIN: 6 ASCII digits.
eiin String?
addressBn String? @map("address_bn")
addressEn String? @map("address_en")
addressBn String? @map("address_bn")
addressEn String? @map("address_en")
/// 5-15 ASCII digits with an optional leading + (a Bangladeshi mobile is stored as E.164).
phone String?
email String?
website String?
headTitleBn String? @map("head_title_bn")
headTitleEn String? @map("head_title_en")
headNameBn String? @map("head_name_bn")
headNameEn String? @map("head_name_en")
establishedYear Int? @map("established_year") @db.SmallInt
logoFileId String? @map("logo_file_id") @db.Uuid
headSignatureFileId String? @map("head_signature_file_id") @db.Uuid
sealFileId String? @map("seal_file_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)
headTitleBn String? @map("head_title_bn")
headTitleEn String? @map("head_title_en")
headNameBn String? @map("head_name_bn")
headNameEn String? @map("head_name_en")
establishedYear Int? @map("established_year") @db.SmallInt
logoFileId String? @map("logo_file_id") @db.Uuid
headSignatureFileId String? @map("head_signature_file_id") @db.Uuid
sealFileId String? @map("seal_file_id") @db.Uuid
/// Fixed kinds (CHECK institute_profiles_file_kinds), part of each image's foreign key, so a
/// logo is a LOGO file, the signature a SIGNATURE and the seal a SEAL.
logoFileKind StoredFileKind @default(LOGO) @map("logo_file_kind")
signatureFileKind StoredFileKind @default(SIGNATURE) @map("head_signature_file_kind")
sealFileKind StoredFileKind @default(SEAL) @map("seal_file_kind")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)

tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Restrict, onUpdate: Restrict)
logoFile StoredFile? @relation("InstituteProfileLogo", fields: [tenantId, logoFileId], references: [tenantId, id], onDelete: Restrict, onUpdate: Restrict)
signatureFile StoredFile? @relation("InstituteProfileSignature", fields: [tenantId, headSignatureFileId], references: [tenantId, id], onDelete: Restrict, onUpdate: Restrict)
sealFile StoredFile? @relation("InstituteProfileSeal", fields: [tenantId, sealFileId], references: [tenantId, id], onDelete: Restrict, onUpdate: Restrict)
logoFile StoredFile? @relation("InstituteProfileLogo", fields: [tenantId, logoFileId, logoFileKind], references: [tenantId, id, kind], onDelete: Restrict, onUpdate: Restrict)
signatureFile StoredFile? @relation("InstituteProfileSignature", fields: [tenantId, headSignatureFileId, signatureFileKind], references: [tenantId, id, kind], onDelete: Restrict, onUpdate: Restrict)
sealFile StoredFile? @relation("InstituteProfileSeal", fields: [tenantId, sealFileId, sealFileKind], references: [tenantId, id, kind], onDelete: Restrict, onUpdate: Restrict)

@@unique([tenantId, id])
// One file is used in one place (also each foreign key's index).
@@unique([tenantId, logoFileId])
@@unique([tenantId, headSignatureFileId])
@@unique([tenantId, sealFileId])
@@unique([tenantId, logoFileId, logoFileKind])
@@unique([tenantId, headSignatureFileId, signatureFileKind])
@@unique([tenantId, sealFileId, sealFileKind])
@@map("institute_profiles")
}
Loading