Repository navigation
Conversation
commit: |
Code Review by Qodo
1. Validator contains comment noise
|
4945bb2 to
826c828
Compare
PostgresDriver and CockroachDriver appended `(length)` to any column
carrying a `length`, without checking whether the type accepts one, so
`createFullType({ type: "uuid", length: "36" })` produced `uuid(36)` -
not a valid type. Both drivers already declare the types that do accept
a length via `withLengthColumnTypes`, which the check now consults.
The other drivers are unaffected: mysql, oracle and sqlserver render
through `getColumnLength()`, and the types that take no length there
normalize to ones that do (mysql maps `uuid` to `varchar` before this
point).
Closes typeorm#12741
826c828 to
2515fb1
Compare
|
@alumni is there a timeline, when and if you intend to release this fix? |
…none
Rendering was only one of three places a length reached. `uuid(36)` could no
longer be produced, but the column still could not be defined: the validator
rejected it up front, and had it passed, `getColumnLength` would have reported
the declared length while postgres reports none for such a column, so it read
as changed on every synchronization and generated a destructive `DROP COLUMN`
plus re-`ADD`.
Whether a type accepts a length is a property of the driver, not of the entity.
`uuid` normalizes to `varchar` on mysql, where a length applies, and stays
native on postgres, where it does not, and the same holds for other types
across the drivers typeorm supports. Rejecting the length made such a column
undefinable for a codebase targeting more than one driver, with no portable
alternative: a per-driver column type is not expressible, since the entity
classes are shared.
The length is now ignored consistently, so carrying one is harmless: it is not
rendered, not rejected, and not reported for comparison. `normalizeType` is
consulted rather than the raw type, so a column declared with a constructor
(`@Column({ length: 255 })` on a string property arrives as String) still
reports its length.
Verified against postgres 18 and mysql 9: one entity declaring
`{ type: "uuid", length: 36 }` yields a native `uuid` on postgres and
`varchar(36)` on mysql, with zero drift over repeated synchronizations, while
varchar, char, array and numeric columns are unaffected.
f332338 to
8349db1
Compare
#3409) Pinning `length: 36` needs three changes in typeorm, not one. Postgres must stop rendering the length (typeorm/typeorm#12742), stop rejecting it in `EntityMetadataValidator`, and stop comparing it in `getColumnLength`. The third is the one that decides feasibility and is unwritten: `getColumnLength` returns the metadata length while postgres reads back none, so with only the first two the column is seen as changed on every boot and generates a destructive `DROP COLUMN` plus re-`ADD`. Verified by simulating each part against postgres 18: parts 1+2 drift 2 statements per pass indefinitely, all three converge to 0.
Use each driver's normalized length allowlist consistently during type rendering and schema comparison. Preserve driver-specific defaults, including generated UUID widths, while native MariaDB UUID remains lengthless. Add cross-driver unit and schema coverage and document the ignored option.
Align the typeorm#8832 regression with the relaxed validator contract. Physical native types remain lengthless and are covered by the schema drift test.
…ort it in postgres
Geometry/geography (and other) column types have no precision or scale in
the Postgres catalog, so the value from entity metadata (for geometry, used
only to control ST_AsGeoJSON precision on read) never matches what is
introspected back. findChangedColumns therefore always reported such columns
as changed, causing the schema builder to drop and recreate related foreign
keys, composite indices, and composite unique constraints, and emit a no-op
ALTER TABLE ... ALTER COLUMN ... TYPE ...
on every synchronize/migration:generate.
Only compare precision when the column type is in withPrecisionColumnTypes,
and scale when it is in withScaleColumnTypes, mirroring how length is handled
generically in typeorm#12742. The same guard is applied to the precision/scale
branch of PostgresQueryRunner.changeColumn.
Closes typeorm#12800
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
This repository was recently restructured into a pnpm workspace, and the If your branch has diverged enough that a full rebase isn't worth it, Sorry for the disruption, and thanks for your patience. |
Closes #12741
What
A
lengthon a column type that accepts none reaches validation, DDL rendering, and schema comparison. All three paths now ignore it consistently.Every schema-backed driver consults its normalized
withLengthColumnTypesallowlist before honoring a declared length. This keeps one shared entity portable across dialects:{ type: "uuid", length: 36 }becomes nativeuuidon PostgreSQL and MariaDB, while MySQL usesvarchar(36). Driver defaults such as generated UUID widths remain intact.Schema comparison now uses
getColumnLength()instead of raw metadata in PostgreSQL, CockroachDB, Aurora MySQL, SQLite, and React Native, closing the remaining perpetual-drift paths. PostgreSQL and CockroachDB also match directTableColumntype names case-insensitively.The public column-option docs now state that an unsupported length is ignored.
Tests
getColumnLengthandcreateFullTypeunit matrix across PostgreSQL/Aurora, CockroachDB, MySQL/Aurora, Oracle, SQL Server, SAP, Spanner, SQLite, and React NativeLocal verification: 254 unit tests and 16 entity-metadata-validator/schema tests pass;
tsc --noEmit, targeted Prettier, and ESLint complete with zero errors. Live PostgreSQL 18, MySQL 9, MariaDB 10.11, and sql.js runs all report zero follow-up schema queries.