Schema & migrations
Exercise35 min
Schema & migrations
An ORM maps classes to tables, and migrations are the ORM's diary:
@Entity('books')
export class Book {
@PrimaryGeneratedColumn() id!: string;
@Column() title!: string;
@ManyToOne(() => Author) author!: Author;
}Write the entity, run migration:generate, review the SQL it produced, then migration:run. The migration file is now history: any teammate or CI can rebuild the exact schema with one command — including this app's roadmap tables, seeded exactly the way you see them.
Never edit a migration that others have run; add a new one instead. History is append-only.
Exercise
In this repo, read migrations/1731300000000-AddContentMetaColumns.ts and its down(). Explain what the pair guarantees.
Practice in the diagram lab
This lesson's practice belongs in the diagram editor — design the schema you just read about, grade it against the solution, and save it to your account.
Open the diagram lab