Skip to content

Database Schema

PostgreSQL with the pgvector extension (required for face embedding storage).

Schema files live in packages/db/src/schema/ — one file per domain entity. After any schema change, run pnpm --filter=@repo/db db:generate and commit the generated migration.

All tables use:

  • UUID primary keys (uuid_generate_v4())
  • createdAt timestamp (default now)
  • updatedAt where rows are updated
  • deletedAt (soft delete) where applicable

Users & Auth

users

End user accounts.

ColumnTypeNotes
iduuid PK
namevarchar(255)
emailvarchar(255)unique
password_hashtextbcrypt
addresstextnullable
billing_addresstextnullable
created_attimestamp

operators

Operator accounts (manage projects, photographers, packages).

ColumnTypeNotes
iduuid PK
namevarchar(255)
emailvarchar(255)unique
password_hashtextbcrypt
currencyvarchar(3)ISO 4217, default from IP geo
localevarchar(10)BCP 47
timezonevarchar(64)IANA timezone
profile_picture_urltextnullable
created_attimestamp

photographers

Photographers belong to an operator.

ColumnTypeNotes
iduuid PK
operator_iduuid FK → operatorsindexed
namevarchar(255)
emailvarchar(255)unique
password_hashtextbcrypt
addresstextnullable
created_attimestamp

Projects

projects

ColumnTypeNotes
iduuid PK
operator_iduuid FK → operatorsindexed
namevarchar(255)
location_namevarchar(255)nullable
start_attimestampnullable
end_attimestampnullable
project_linktextnullable
terms_and_conditionstextnullable
timezonevarchar(64)nullable
created_attimestamp

project_members

Users who have joined a project (via QR).

ColumnTypeNotes
iduuid PK
project_iduuid FK → projectsindexed
user_iduuid FK → usersindexed
joined_attimestamp
terms_accepted_attimestampnullable

Unique index on (project_id, user_id).

project_photographers

Photographers assigned to a project.

ColumnTypeNotes
iduuid PK
project_iduuid FK → projectsindexed
photographer_iduuid FK → photographersindexed

project_packages

Packages linked to a project (composite PK).

ColumnTypeNotes
project_iduuid FK → projects
package_iduuid FK → packages

project_coaches

Coaches associated with a project.

ColumnTypeNotes
iduuid PK
project_iduuid FK → projectsindexed
namevarchar(255)

Media

packages

Pricing packages created by operators.

ColumnTypeNotes
iduuid PK
operator_iduuid FK → operatorsindexed
namevarchar(255)
priceintegerin cents
photo_countinteger
created_attimestamp
updated_attimestamp

photos

Project photos uploaded by photographers.

ColumnTypeNotes
iduuid PK
project_iduuid FK → projectsindexed
photographer_iduuid FK → photographersindexed
storage_keyvarchar(512)R2 key for original
thumbnail_keyvarchar(512)nullable, 400px thumb
watermarked_keyvarchar(512)nullable
statusvarchar(20)processing / ready / failed
uploaded_attimestamp

selfies

User selfies for face recognition.

ColumnTypeNotes
iduuid PK
user_iduuid FK → usersindexed
storage_keyvarchar(512)R2 key
embeddingvector(128)pgvector, from Rekognition
quality_scorerealnullable, Rekognition confidence
statusvarchar(20)pending / approved / rejected
rejection_reasontextnullable
created_attimestamp

photo_tags

Face recognition results linking users to photos.

ColumnTypeNotes
iduuid PK
photo_iduuid FK → photosindexed
user_iduuid FK → usersindexed
confidencerealraw Rekognition score, always stored
sourcevarchar(20)auto / manual
review_statusvarchar(20)confirmed / pending / rejected
created_attimestamp

WARNING

Only confirmed tags are visible to end users. pending tags are in the manual review queue.


purchases

ColumnTypeNotes
iduuid PK
user_iduuid FK → usersindexed
project_iduuid FK → projectsindexed
package_iduuid FK → packagesindexed
stripe_payment_intent_idvarchar(255)unique
statusvarchar(20)pending / paid / failed
created_attimestamp

user_consents

Biometric processing consent records.

ColumnTypeNotes
iduuid PK
user_iduuid FK → usersindexed
consent_typevarchar(50)e.g. biometric_processing
consent_versionvarchar(20)
given_attimestamp
revoked_attimestampnullable — null means active

qr_tokens

Short-lived tokens embedded in project QR codes.

ColumnTypeNotes
iduuid PK
project_iduuid FK → projectsindexed
tokenvarchar(255)unique
expires_attimestamp
used_attimestampnullable
created_attimestamp

Acme Photo Platform — Internal Documentation