Data access patterns, Scaling, Migrations, and ORM selection.
Integration patterns and ORM standards for PostgreSQL applications.
See references/best-practices.md for database selection matrix and scaling patterns (Connection Pooling, Sharding).
@InjectRepository(Entity).PrismaService.TypeOrmModule.forRootAsync to load secrets from ConfigService.synchronize: false in production; use migrations instead.synchronize: true in production..entity.ts) is modified, a migration MUST be generated using pnpm migration:generate.pnpm migration:run in a pre-deploy or post-deploy job (e.g., GitHub Actions, GitLab CI). Ensure the production environment variables are correctly set.typeorm migration:show to get the SQL or simply copy the up method's SQL into a management tool (like Supabase SQL Editor). Always track manual runs in the migrations metadata table.typeorm migration:generate cannot detect RLS policies (CREATE POLICY). You MUST use migration:create and write raw queryRunner.query() SQL to define and version-control RLS policies.where, order by).QueryRunner (TypeORM) or $transaction (Prisma) for all multi-step mutations to ensure atomicity.WHERE tenant_id = current_setting('app.tenant_id')).user_id or tenant_id).JOINs or subqueries inside the RLS policy definition itself, as this can multiply execution time heavily. Keep policies simple (direct column comparisons).