Last 12 weeks · 11 commits
4 of 6 standards met
Report hasn't been filed before. [x] I have verified that the bug I'm about to report hasn't been filed before. What version of are you using? 1.0.0-rc.4 What version of are you using? 1.0.0-rc.4 Other packages _No response_ Describe the Bug What is the undesired behavior? When renames a column in one table, column-level alterations on a column with the same original name in a different table are missing from the generated SQL. The snapshot is correct (e.g. ), so the next produces no diff and the change is silently lost. It also happens on . Affected (missing from SQL): , , , . Not affected (generated correctly): unique, foreign key (incl. changes), index, check. What are the steps to reproduce it? 1. Initial schema, run : 2. Rename to and drop on : 3. Run and choose rename column () at the prompt. Generated SQL: What is the desired result? Additional details If the renamed column in has a different original name (e.g. → ), the alteration on is generated correctly. If create column is chosen instead of rename at the prompt, the alteration is generated as well. It looks like renamed columns are matched by column name only, without the table name, so the alteration on gets consumed by the rename of . Possibly related to #3826 (marked as fixed in ). That issue is about alterations on the renamed column itself being dropped; here the lost alterations belong to a column in a different table that shares the renamed column's old name. Database: PostgreSQL (local, Docker), driver . Node.js, no monorepo.
Report hasn't been filed before. [x] I have verified that the bug I'm about to report hasn't been filed before. (#800 is related but broader and is closed.) What version of are you using? 0.45.2. 0.45.3 (current ) has byte-identical and , so it is affected too. 1.0.0-beta.22 and 1.0.0-rc.4 are not affected. What version of are you using? Not involved. This is type-checking only. Other packages typescript 5.6.3; also reproduced with typescript 7.0.2 (native). Node 24. Describe the Bug On 0.45.x, the cost of resolving for a whose columns are mostly nullable grows as about 27.6 · N² type instantiations in the column count N. At 424 columns, one expression passes TypeScript's per-expression limit of 5,000,000 instantiations and fails: for the same table stays linear. At N = 426 it costs 162k instantiations when every property is resolved, and 12k to read one property, against 5.0M for . The error does not stay in the schema file. Anything that relates the table to / resolves : / , , or generic helpers that take . So TS2589 surfaces in whichever file touches the table first. Before the limit, the cost already shows up as check time and editor latency: about 20 s for a single probe file at N = 426. Measurements (0.45.2, TypeScript 5.6.3) Each figure is from , minus a baseline program with the same table and no probe. The synthetic table has a primary key and N−1 nullable columns with no default, cycling through , , , , , , , and . TS2589 threshold, found by binary search with the same generator: TypeScript 5.6.3: passes at 423 columns and fails at 424; assignment passes at 424 and fails at 425. TypeScript 7.0.2 (native): passes at 437 columns and fails at 438; assignment passes at 433 and fails at 434. TS 7 counts about 2% fewer instantiations (4,937,080 against 5,057,848 in total at N = 426), but the 5M limit is the same, so upgrading TypeScript moves the threshold only a few columns. The column mix changes the constant. With a four-way cycle of none / / / both, N = 426 costs 942k instead of 5.0M. The quadratic still applies, but with a smaller constant. The worst case is a wide table of nullable columns without defaults, which is what legacy and "profile"-style tables tend to look like. Cause is , where is and in 0.45.x Splitting it apart at N = 426 (Δ instantiations): So is not the expensive part by itself. It is what makes every access resolve the type of every property of , as a spread or a structural comparison does. The quadratic cost lies in resolving all properties of the mapped type. Narrowing further at N = 300, with the same mapped type and only the key filter varied: The trigger is a distributive conditional alias whose check type is the key parameter () used in a mapped-type clause. The same conditions are cheap when they are inlined, or when the check type is the column. I have not traced the exact checker path. It is already fixed on 1.0, so please backport In 1.0.0-beta.22 and 1.0.0-rc.4, defines both helpers with the column's config as the check type: The same repro on 1.0.0-rc.4 is linear: costs 35.7k over baseline at N = 426, 82.8k at N = 1000, and 164.8k at N = 2000, with no TS2589. Dropping just these two definitions into 0.45.2, with and everything else unchanged: gives the same public type. holds for a table that covers , both identity kinds, , , , , , and , with and . A negative control fails as expected. cuts the cost at N = 426 from 5,004k to 194k** (read ) and from 5,107k to 203k (), about 25× less. A 0.45.x patch release with this change would unblock projects that cannot move to 1.0 yet. Expected behavior should cost about the same as , linear in column count, as it already does on 1.0. It should not fail with TS2589 on a table of a few hundred columns. Environment & setup A standalone repro with no framework and no database: an empty folder, , and these three files. , which writes with N columns and : Swap in to see the linear behaviour. Known workarounds on 0.45.x: keep tables under about 400 mostly nullable columns, or split them. Annotating call sites with does not help, because relating the table to / resolves anyway. A local of with the 1.0 definitions above works.
ORM Updated RQB filters to allow branded types in shortcut-form filter (fixes #5298) Fixed being executed without need (fixes #5780) Fixed potentially overriding explicit s Fixed schema generator returning -templated coerced types (fixes #5659) Fixed constructor setting param in potentially undefined mistyped config (fixes #5972) Fixed non-jit mapper nullification triggering on single null column (fixes #1603) Preserved qualifiers for column chunks of fields in selection when non-current table's column is referenced (fixes #5734) Optimized query building, mapper generation Allowed empty returns in callback-style , , of relational queries Removed unused field in Restricted value passed to fields in - now throws an error upon encountering in filters, added symbol that can be used as an explicit replacement of where possibly absent filter is desired by design rather than possible bug (fixes #5636) Fixed naming: to in , modes (, in ) (bypasses #4464) Fixed jit mapper nullifying nested selection objects with columns from different tables Updated codecs: now generic codecs contain only in-json codecs (mirroring ), contents of drivers' codecs remain unchanged Made nested select join nullification consider field data during nullification Deeply nested selection nullification (joined view or subquery) Fixed , & array types data getting reduced to one item due to wrong delimiter used during construction\parsing Added delimiter customization to , utilities Optional explicit column lists for (workaround for #5001, #5309) Transaction snapshot support for dialect Fixed transaction config related errors on empty but present config (fixes #1772) Supported transaction config in effect drivers Bump library versions Supported transaction configs for drivers Fixed transaction options being joined on wrong separator Supported in transactions Removed transaction config from , due to lack of support in drivers Explicit error throws on unsupported transaction configs Partial transaction config support for , drivers Improved error messages on unknown fields in RQBv2 selection (fixes #5367) Fixed transaction being handled as synchronous Fixed broken query executors (fixes #5936) Bumped to v17 (fixes #5928) Fixed not finalizing prepared statements Added for async querying (fixes #5240) Added local hash function as a fallback for cache query hashing in environments without available Fixed dynamic query builders blocking query builder's variable reassignment after applying nullable joins by defaulting to behavior on not yet joined column groups in selection (fixes #4232) Fixed not being included in table creation callback format column list Fixed ignoring on insert when is present Removed calculation from constructor to getter Fixed false relation name collision error and relational filter misrouting for relation names shadowing properties like (fixes #6076) Updated migrator to automatically rollback failed migrations Bump to (fixes #6162) Improved hash for query name generation & query cache key Bump to (fixes #5981) Fixed internal type errors in built code Updated , , sessions to new format Added missing (), joins, , to Added explicit error on attempt to insert multiple default-only rows in Fixed columns on React Native drivers: writes no longer require , and reads normalized to . Use to override column's type Reworked column builders to mirror - now both have same Fixed cast codecs being applied to selection fields of inner queries in , Fixed double space following in set operation queries Fixed , , types returning different types based on column's value Untied , , column mapping from connection config, removed forced params on their respective configs, replaced with more stable codecs Fixed generating , queries with on columns Codec system for , , , Migrated , to RQBv2 Removed redundant from relational , for json arrays in in RQBv2 Fixed drivers setting raw execute result to type passed in template instead of Removed RQBv1 from Fixed not using from config over driver's default when provided Added delimiter customization to , utilities, mirroring their counterparts Fixed arrays being unwritable due to wrong delimiter Fixed array parser dropping backslashes from string values Fixed being parsed to Added caching for queries reused without Fixed table extra config not rejecting unsuitable for field values (fixes #6140) Fixed subquery derived from query builder being unusable with , (fixes #4069) Fixed field described as instead of ; Set field to and marked as to prevent field from bleeding into relational filters' autocomplete Fixed (fixes #2174) Fixed relational queries not supporting type fields in s Updated class: switched to -like object config for type template, typed property Moved exports from to Fixed function returning materialized views typed as regular views Added typed type config property to , to identify if it was aliased no longer prefixes aliased views or tables with their no longer sets prefix for entities without Added , utils, supported in util Supported as relational entity in RQBv2: must have flat selection, same as Every used will be invoked only once in section on root level of relational query, every reference will use it's alias Same query can't have reference multiple instances with same alias Fixed excessive memory consumption on , , iterators Fixed iterators leaving connection un-drained & deadlocked on errors Fixed recursing into stack overflow (fixes #6050) Updated (indirectly fixes #4185): Now every query goes to primary db by default To query replica, explicitly call Fixed dropping from return type of Fixed dropping from return type of with or present, (fixes #6107) Fixed select codecs leaking into builders passed as sql operator argument Added switch to , switch to of non-relational query builders - now emits query without cast codecs by default Fixed = , = mimic , different data view type collisions in (fixes #5842) Fixed concurrent query + cache invalidation run (fixes #5828) Fixed transparent parsers set by constructors breaking driver's own serializers for , , , , , types (fixes #3171, #4426, #5789) :exclamation: Any existing workarounds with manual in raw sql or raw driver calls must be removed to prevent double stringification of JSON params; For array-type JSON params in use to avoid it being parsed as value list instead of param. Supported adapters for () - , () - Fixed param codecs getting applied to inlined params Reworked : Added switch for execute methods Dropped callback result wrapping - now expected direct return of expected data Replaced , with object - must provide , , handlers & optional handler Dropped execute method due to it being duplicate of array-mode Added type inferrence based on return type of executor, updated template with argument Added per-item to , is expected to mirror executors' return types per query Fixed runtime-type expected result mismatch for ( in runtime, in types) (fixes #5461, #3394) Reworked types (fixes #661): Plain - returns union every possible response type by driver returns rowless response type (i.e. without ) driver response with rows typed as Fixed type template rejecting interfaces Typed drivers' raw , (fixes #6382) Fixed [[BUG]: inArray/notInArray empty arrays do not work with SQL Server](https://github.com/drizzle-team/drizzle-orm/issues/5632) Fixed [[BUG]: node-postgres pool client is not released when transaction BEGIN rejects](https://github.com/drizzle-team/drizzle-orm/issues/6023) Fixed Batch insert crashes with RangeError when row-count × column-count exceeds ~8 k rows × 15 cols (~120 k params) Fixed [[BUG]: Composition of not and or/and yields compile error](https://github.com/drizzle-team/drizzle-orm/issues/4160) Fixed [[BUG]: Negative limit not working in SQLite](https://github.com/drizzle-team/drizzle-orm/issues/2992) Fixed [[BUG]: Pooled transaction() leaks the pool client when BEGIN fails (node-postgres / neon-serverless / vercel-postgres)](https://github.com/drizzle-team/drizzle-orm/issues/6241) Fixed [[BUG]: node-postgres transaction() leaks the client on a rejected BEGIN and returns broken clients to the pool](https://github.com/drizzle-team/drizzle-orm/issues/6114). node-postgres: transaction() runs BEGIN before try/finally, leaking the pool client when BEGIN fails Kit: Added support for custom PGLite options (fixes #2995, #4476 and #3222) Fixed allowing fields from every config variant simultaneously Fixed [[BUG]: SQLite push glues the table's FOREIGN KEY clause onto a generated-column ALTER ADD, breaking all inserts](https://github.com/drizzle-team/drizzle-orm/issues/6061) Fixed [[BUG]: SQLite push table recreate silently drops UNIQUE from a column that also has a plain index](https://github.com/drizzle-team/drizzle-orm/issues/6060) Fixed [[BUG]:drizzle-kit generates DROP COLUMN before DROP INDEX causing PostgreSQL error 42704](https://github.com/drizzle-team/drizzle-orm/issues/6045) Fixed [[BUG]: false positve detection of schema changes for default values](https://github.com/drizzle-team/drizzle-orm/issues/5569) Fixed [[BUG]: drizzle-kit pull rewrites "character" inside public enum type names to "char"](https://github.com/drizzle-team/drizzle-orm/issues/5932) Fixed [[BUG]: drizzle-kit pull error when there are comments in a view definition](https://github.com/drizzle-team/drizzle-orm/issues/5964) Fixed [[BUG]: Invalid schema default value generated for sequence-based primary keys in Postgres](https://github.com/drizzle-team/drizzle-orm/issues/5413) Fixed Small typo in drizzle-kit/src/index.ts Fixed [[BUG]: drizzle-kit pull reports index_duplicate for valid MSSQL index names reused across tables](https://github.com/drizzle-team/drizzle-orm/issues/5993) Fixed [[BUG]: drizzle-kit pull generates many() instead of one() for one-to-one relations (unique FK columns)](https://github.com/drizzle-team/drizzle-orm/issues/5478) Fixed [[BUG]: AWS Data API Postgres - incompatibility with latest @aws-sdk/client-rds-data (3.932.0) ](https://github.com/drizzle-team/drizzle-orm/issues/5050) Fixed [[BUG]: Composition of not and or/and yields compile error](https://github.com/drizzle-team/drizzle-orm/issues/4160) Fixed [[BUG]: snakeCase.table converts Korean column names to empty identifiers](https://github.com/drizzle-team/drizzle-orm/issues/6082) Fixed [[BUG]: Property decimal does not exist on type, when using pgTable in drizzle orm](https://github.com/drizzle-team/drizzle-orm/issues/3059) Fixed Bug: drizzle-kit pull for SQLite Generates Constraints from Comments in Schema Fixed [[BUG]: drizzle-kit pull fails with column_unsupported_unique for unique indexes on text/mediumtext/longtext columns](https://github.com/drizzle-team/drizzle-orm/issues/6047) Fixed [[BUG]: drizzle-kit CLI pull/introspect schemaFilters parameter is ignored](https://github.com/drizzle-team/drizzle-orm/issues/3626) Fixed [[BUG]: Changing a view to materialized view doesn't generate correct migration](https://github.com/drizzle-team/drizzle-orm/issues/6176) Fixed [[BUG]: SQLite incorrectly scaffolds boolean column with drizzle-kit pull](https://github.com/drizzle-team/drizzle-orm/issues/6182) Fixed [[BUG]: Introspection fails if SQLite database has a references without column name](https://github.com/drizzle-team/drizzle-orm/issues/3231) Fixed [[BUG]: SQLite pull drops or merges CHECK constraints depending on DDL formatting](https://github.com/drizzle-team/drizzle-orm/issues/6195) Fixed [[BUG]: SQLite pull reads a partial index's WHERE off the table's DDL, losing real predicates and inventing false ones](https://github.com/drizzle-team/drizzle-orm/issues/6223) Fixed [[BUG]: drizzle-kit pull generates a many-to-many whose junction table is one of its own endpoints, and drops the one-relations the foreign keys describe](https://github.com/drizzle-team/drizzle-orm/issues/6197) Fixed [[BUG]: drizzle-kit push tries to DROP Neon system roles despite provider: "neon"](https://github.com/drizzle-team/drizzle-orm/issues/6105) Fixed [[BUG]: drizzle-kit pull crashes on MSSQL when tablesFilter excludes referenced FK table](https://github.com/drizzle-team/drizzle-orm/issues/5992) Fixed [[BUG]: drizzle-kit pull generates invalid through relations for composite foreign keys](https://github.com/drizzle-team/drizzle-orm/issues/6100) Fixed [[BUG]: drizzle-kit pull: schema and relations disagree on camelCase for acronym columns (CallID → callId vs callID)](https://github.com/drizzle-team/drizzle-orm/issues/6074) Fixed [[BUG]: drizzle-kit pull drops single-column PK/FK constraint names from schema.ts (kept nameExplicit in snapshot) — pull→generate demands rename-or-create hints for every legacy-named constraint](https://github.com/drizzle-team/drizzle-orm/issues/6025) + [[BUG]: Drizzle Kit introspection creates different foreign key names than migration](https://github.com/drizzle-team/drizzle-orm/issues/1549) Updates in pull relations logic. TS file generates junction tables only when there are no extra columns in this junction table. Fixed [[BUG]: drizzle-kit pull treats domain tables with exactly two foreign keys as junction tables](https://github.com/drizzle-team/drizzle-orm/issues/6253) Fixed [[BUG]: drizzle-kit pull fails with a confusing error if the database can't be reached](https://github.com/drizzle-team/drizzle-orm/issues/6362)
Fixes #6253 Summary classified every table with exactly two foreign keys as a many-to-many junction, as long as the FKs pointed at two different non-self tables. That is too weak. A domain entity can legitimately reference exactly two other tables and still have its own identity. The generator then: Invents a relation between the two referenced tables Drops the relations on the domain table Can leave reverse relations unresolvable () This is the same 2-FK trigger as #6197 (self-ref, already skipped) and #6100 (composite through template). #6253 is the remaining case: extra columns / own PK. Heuristic A table is a junction only when all of these hold: 1. Exactly two foreign keys 2. Those FKs point at two different other tables (not self) 3. Every column on the table is one of those FK columns Otherwise emit the normal / pair for each FK. A classic join table still becomes a relation. with , , , … becomes: transactionRecord: { account: r.one.account({ from: r.transactionRecord.accountId, to: r.account.id }), category: r.one.category({ from: r.transactionRecord.categoryId, to: r.category.id }), }, account: { transactionRecords: r.many.transactionRecord() }, category: { transactionRecords: r.many.transactionRecord() }, SQLite and Cockroach now pass into so the extra-column check can see them (Postgres/MySQL already did). Tests Unit: (4 passed) #6253 domain table (extra columns) own PK + two FKs, no extra business columns pure join table still #6197 self-ref still not a junction Postgres pull: issue 6253 SQL repro + a pure-junction control Existing #5493 relations-issue test still loads pnpm vitest run tests/other/relations-to-typescript.test.ts pnpm vitest run tests/postgres/pull.test.ts -t 'issue 6253relations issue' Related #6253 — this PR #6197 — self-ref 2-FK (already on ) #6100 / #6111 — composite through column pairing (separate) Agent disclosure Written by an AI agent on behalf of @devtechedge, who has reviewed this pull request.
Repository: drizzle-team/drizzle-orm. Description: ORM Stars: 35910, Forks: 1669. Primary language: TypeScript. Languages: TypeScript (98.7%), JavaScript (1.3%). License: Apache-2.0. Homepage: https://orm.drizzle.team Topics: bunjs, mysql, nodejs, orm, postgres, postgresql, sql, sqlite, turso, typescript. Latest release: drizzle-kit@0.31.11 (1w ago). Open PRs: 100, open issues: 1977. Last activity: 1d ago. Community health: 87%. Top contributors: AndriiSherman, dankochetov, L-Mario564, AlexBlokh, Sukairo-02, Angelelz, AleksandrSherman, OleksiiKH0240, RomanNabukhotnyi, realmikesolo and others.