Context
We are migrating a backend from Laravel (PHP) to NestJS (Node.js) while continuing to use the same existing MySQL database.
The database is large and legacy, with:
Hundreds of tables
Some tables without primary keys
Columns with complex or non-standard defaults (e.g., JSON stored in
VARCHAR)A schema too large to comfortably manage in a single ORM schema file (≈19k+ lines)
Because of this size, Prisma was not suitable, so we decided to use TypeORM.
What We Tried
We attempted a DB-first approach using:
typeorm-model-generator@0.4.6
Node.js v24.x
MySQL 8.x
NestJS + TypeORM
Issues Encountered
Tables without primary keys
typeorm-model-generatorfails or stops generation with:Tablehas no PK. These tables already exist and are used by the application.
Invalid generated TypeScript for certain defaults
Example:
default: () => "'{"key":"value"}'"This causes Prettier / TypeScript parse errors and breaks generation.
Manual entity creation is not viable
Recreating entities table-by-table introduces schema drift
Duplicate entities per module become hard to maintain
Why This Is a Problem
The database schema cannot be immediately redesigned because we have around 300 tables
Adding PKs or normalizing all tables is risky during migration
We want a safe, incremental migration strategy
We need to avoid runtime corruption or silent bugs
Question
- What is the recommended approach for using TypeORM with a large legacy MySQL database that ?
Constraints
DB schema changes must be minimal during migration
Data integrity is critical
Long-term maintainability is the goal