Week 2 — PostgreSQL & TypeORM
Learn SQL first, then connections (pool/SSL), then TypeORM entities, repos, migrations, seeds, relations, and transactions — then ship Notes P2 as this week’s mini-project.
- 1. Tables & columnsOpen
Everything else in this week — keys, joins, TypeORM entities — is just more structure on top of tables and columns. Read raw SQL before you read decorators.
- 2. Primary & foreign keysOpen
Keys are what turn separate tables into a connected schema. tickets.assignee_id pointing at users.id is the whole relationship this app is built around.
- 3. SQL CRUDOpen
Before TypeORM writes any of this for you, know what the actual SQL looks like — it is what a Repository call or QueryBuilder produces under the hood.
- 4. JoinsOpen
This app’s core relationship — a ticket and its assignee — lives across two tables. A join is how you see both together in one query.
- 5. DB connections: URL, pooling, SSL, timeoutsOpen
Before Nest or TypeORM enter the picture, understand what DATABASE_URL actually configures, why pooling exists, and what happens when an app misuses connections.
- 6. Nest ↔ PostgreSQL: TypeORM root/envOpen
This is where the SQL-level concepts (URL, entities-as-tables, no synchronize) become one concrete Nest config object.
- 7. EntitiesOpen
User and Ticket in this repo are the entities behind every users/tickets row you have already seen in raw SQL.
- 8. Repositories / QueryBuilderOpen
This is the layer that TicketsService actually uses — @InjectRepository(Ticket) gives it a Repository<Ticket>, wired up via TypeOrmModule.forFeature in the feature module.
- 9. Migrations (deep dive)Open
This is the single most important backend habit in the course: schema changes are files you review, not something TypeORM infers silently.
- 10. SeedersOpen
This course’s seed script is exactly how admin@course.local and member@course.local (password123) get into a fresh database.
- 11. Relationships: 1:1, 1:N, N:NOpen
This repo has a real 1:N relationship (User ↔ Ticket) — 1:1 and N:N are covered here as patterns you will need for other features, shown as illustrative extensions of this same schema.
- 12. Transactions & multi-write consistencyOpen
Repository/QueryBuilder calls outside a transaction each commit independently; TypeORM gives you an explicit way to group writes when that independence would be a bug.
- 13. Notes API — Postgres + TypeORM milestoneOpen
Maps to Week 2 SQL + TypeORM. Use W3Schools SQL/PostgreSQL under /resources if you need query refreshers.
End-of-week mini-project · practice only
Notes API — Postgres + TypeORM (P2)
Persist Notes with entities, migrations, seed, and a User↔Note relation (synchronize: false).
Definition. Week 2’s mini-project is Notes P2: PostgreSQL persistence via TypeORM with reviewed migrations and seed data.
In simpler words. Replace in-memory habits with real tables. Prove it with the P2 grader.
Deliverables
- Note + User entities; author ManyToOne
- Migration + seed; synchronize false in AppModule and data-source
- List loads author without N+1
Acceptance checklist
- [ ] SQL/Postgres refreshers under /resources if needed
- [ ] Migration reviewed before run
- [ ] pnpm course:validate-milestone be-notes-p2 is green
- [ ] Open topic be-notes-p2 for full acceptance detailTips
- Never turn synchronize true “just for practice”.
- W3Schools SQL + PostgreSQL links are on /resources.