Database Information
Structure
Section titled “Structure”Column Ordering Conventions
Section titled “Column Ordering Conventions”-
Identifiers first
id(primary key)- foreign keys (
user_id,project_id)
-
Core business fields
- fields that define the record itself
-
Metadata / bookkeeping
created_atupdated_atdeleted_atversion- audit columns
-
Rarely used or optional fields last
Why: cleaner to scan, PK/FK grouping improves clarity, aligns with common tool-generated structures.
Drizzle ORM
Section titled “Drizzle ORM”Drizzle is the chosen ORM for this project. It seems a good transition from the sql code from access, using the sql like syntax. Also good performance and zod integration.
Structure
Section titled “Structure”drizzle
Section titled “drizzle”The drizzle folder is outside of source, at root level. It is used for migrations and type checking during development, but not during runtime.
The drizzle inastance is created in src/db.
Migrations
Section titled “Migrations”For an existing database (initial):
- run
db:dev:push, will fail at creating relations to users - run
db:seed, adds the initial users (including me at the proper id) - run
db:dev:push, now the relations are created - add emailVerification date to users (optional)
Utilities
Section titled “Utilities”// /utils/db.utils.ts
function transformUserId(userId: unknown): UserIdTypeThis function infers the type directly from the users.id field in the db. Use for every call that needs a user id and it will gurantee the type.