You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(codemod): rename .connection on EntityMetadata, ColumnMetadata, IndexMetadata - #12383
Reported by Lucian: meta.connection.getMetadata(...) was left unchanged when meta is typed EntityMetadata. Same for ColumnMetadata and IndexMetadata.
connection-to-datasource already renames .connection → .dataSource on typed references to QueryRunner, EntityManager, Repository, TreeRepository, MongoRepository, and the *QueryBuilder classes. The metadata classes were missed — their .connection property was renamed to .dataSource in #12249, same breaking change.
Extends typesWithConnectionProp with EntityMetadata, ColumnMetadata, and IndexMetadata. Fixture gains typed-parameter cases for EntityMetadata and ColumnMetadata to pin the behavior.
1. Broken metadata rewrite 🐞 Bug≡ Correctness⭐ New
Description
Adding ColumnMetadata and IndexMetadata to typesWithConnectionProp makes the codemod rewrite
x.connection to x.dataSource for those types, but in this repo the DataSource is accessed via
x.entityMetadata.dataSource rather than a dataSource property on
ColumnMetadata/IndexMetadata. The resulting transformed code (and the new fixture expectation)
will not match the actual TypeORM API shape present here.
The transform renames .connection→.dataSource for any identifier whose type annotation name is
in typesWithConnectionProp; this PR adds ColumnMetadata/IndexMetadata to that set. In the
TypeORM sources in this repo, ColumnMetadata and IndexMetadata use entityMetadata.dataSource
(not this.dataSource), and EntityMetadata is the class that actually has the dataSource
property. Therefore rewriting col.connection to col.dataSource is inconsistent with the repo’s
API and will generate invalid output for those metadata objects.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
`connection-to-datasource` now rewrites `.connection` to `.dataSource` on identifiers typed as `ColumnMetadata`/`IndexMetadata`, but in this repo those metadata objects access the DataSource via `entityMetadata.dataSource` (they do not use a `dataSource` property on the metadata object itself). The codemod should not emit `col.dataSource` / `idx.dataSource` for these types.
### Issue Context
- `ColumnMetadata` uses `this.entityMetadata.dataSource` internally.
- `IndexMetadata` uses `options.entityMetadata.dataSource`.
- Only `EntityMetadata` exposes a `dataSource` property directly.
### Fix Focus Areas
- packages/codemod/src/transforms/v1/connection-to-datasource.ts[43-61]
- packages/codemod/src/transforms/v1/connection-to-datasource.ts[180-234]
- src/metadata/ColumnMetadata.ts[16-45]
- src/metadata/ColumnMetadata.ts[349-362]
- src/metadata/IndexMetadata.ts[9-26]
- src/metadata/IndexMetadata.ts[140-157]
- packages/codemod/test/transforms/v1/fixtures/connection-to-datasource/connection-to-datasource.input.ts[21-28]
- packages/codemod/test/transforms/v1/fixtures/connection-to-datasource/connection-to-datasource.output.ts[21-28]
### Concrete direction
1. Track *which* TypeORM type each collected identifier is annotated with (e.g., map `varName -> typeName`).
2. When rewriting `obj.connection`:
- If `obj` is annotated as `EntityMetadata`, rewrite to `obj.dataSource`.
- If `obj` is annotated as `ColumnMetadata` or `IndexMetadata`, rewrite to `obj.entityMetadata.dataSource` (i.e., replace the MemberExpression with a nested MemberExpression chain).
3. Update/extend fixtures to assert the correct rewritten form for `ColumnMetadata`/`IndexMetadata` (and add an `IndexMetadata` case if intended).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. Unscoped metadata type matching 🐞 Bug≡ Correctness
Description
The codemod now renames .connection → .dataSource whenever a variable/param is typed
EntityMetadata/ColumnMetadata/IndexMetadata by name alone, without verifying the type is
imported from typeorm, so unrelated code with those common type names can be rewritten
incorrectly. It also fails to rename real TypeORM cases where these types are imported under an
alias or referenced via a qualified name, because only bare Identifier type references are
recognized.
+ // Metadata classes (renamed in #12249)+ "EntityMetadata",+ "ColumnMetadata",+ "IndexMetadata",
Evidence
The transform collects identifiers to rewrite by checking only the type annotation’s identifier name
against typesWithConnectionProp; it does not check whether that type name came from a typeorm
import. The updated fixture demonstrates this behavior by using EntityMetadata/ColumnMetadata
without importing them, yet expecting .connection to be transformed. Because the check only
matches exact names and only when the type is a bare Identifier, aliased imports (e.g. `import {
EntityMetadata as EM }) and qualified names (e.g. TypeORM.EntityMetadata`) are missed.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`connection-to-datasource` decides whether to rename `.connection` → `.dataSource` by checking only the *spelling* of a type annotation (e.g. `EntityMetadata`) rather than verifying that the type actually comes from TypeORM. Adding `EntityMetadata`/`ColumnMetadata`/`IndexMetadata` increases the chance of false positives because these names are common.
It also produces false negatives for TypeORM metadata types imported under aliases (e.g. `import { EntityMetadata as EM }`) or referenced through a namespace/qualified name.
## Issue Context
The transform already inspects `ImportDeclaration` from `"typeorm"` for other renames, so it can similarly scope `.connection` property rewrites to identifiers whose type annotations refer to a local name imported from `typeorm` (including aliases).
## Fix Focus Areas
- packages/codemod/src/transforms/v1/connection-to-datasource.ts[43-61]
- packages/codemod/src/transforms/v1/connection-to-datasource.ts[63-93]
- packages/codemod/src/transforms/v1/connection-to-datasource.ts[180-234]
- packages/codemod/test/transforms/v1/fixtures/connection-to-datasource/connection-to-datasource.input.ts[1-33]
- packages/codemod/test/transforms/v1/fixtures/connection-to-datasource/connection-to-datasource.output.ts[1-33]
## Concrete implementation notes
- Build a `Set<string>` of *local* type names imported from `"typeorm"` whose `imported.name` is in `typesWithConnectionProp` (so `EntityMetadata as EM` adds `EM`).
- In `collectTypedIdentifier`, match against that local-name set (instead of raw `typesWithConnectionProp`) and consider supporting `TSQualifiedName` for `import * as TypeORM from "typeorm"`.
- Update the fixture to import `EntityMetadata`/`ColumnMetadata` from `typeorm`, and add an alias fixture case (e.g. `EntityMetadata as EM`) to prevent regressions.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
ⓘ The new review experience is currently in Beta. Learn more
Author self-review: I have reviewed the code review findings, and addressed the relevant ones.
1. Unscoped metadata type matching 🐞 Bug≡ Correctness
Description
The codemod now renames .connection → .dataSource whenever a variable/param is typed
EntityMetadata/ColumnMetadata/IndexMetadata by name alone, without verifying the type is
imported from typeorm, so unrelated code with those common type names can be rewritten
incorrectly. It also fails to rename real TypeORM cases where these types are imported under an
alias or referenced via a qualified name, because only bare Identifier type references are
recognized.
+ // Metadata classes (renamed in #12249)+ "EntityMetadata",+ "ColumnMetadata",+ "IndexMetadata",
Evidence
The transform collects identifiers to rewrite by checking only the type annotation’s identifier name
against typesWithConnectionProp; it does not check whether that type name came from a typeorm
import. The updated fixture demonstrates this behavior by using EntityMetadata/ColumnMetadata
without importing them, yet expecting .connection to be transformed. Because the check only
matches exact names and only when the type is a bare Identifier, aliased imports (e.g. `import {
EntityMetadata as EM }) and qualified names (e.g. TypeORM.EntityMetadata`) are missed.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`connection-to-datasource` decides whether to rename `.connection` → `.dataSource` by checking only the *spelling* of a type annotation (e.g. `EntityMetadata`) rather than verifying that the type actually comes from TypeORM. Adding `EntityMetadata`/`ColumnMetadata`/`IndexMetadata` increases the chance of false positives because these names are common.
It also produces false negatives for TypeORM metadata types imported under aliases (e.g. `import { EntityMetadata as EM }`) or referenced through a namespace/qualified name.
## Issue Context
The transform already inspects `ImportDeclaration` from `"typeorm"` for other renames, so it can similarly scope `.connection` property rewrites to identifiers whose type annotations refer to a local name imported from `typeorm` (including aliases).
## Fix Focus Areas
- packages/codemod/src/transforms/v1/connection-to-datasource.ts[43-61]
- packages/codemod/src/transforms/v1/connection-to-datasource.ts[63-93]
- packages/codemod/src/transforms/v1/connection-to-datasource.ts[180-234]
- packages/codemod/test/transforms/v1/fixtures/connection-to-datasource/connection-to-datasource.input.ts[1-33]
- packages/codemod/test/transforms/v1/fixtures/connection-to-datasource/connection-to-datasource.output.ts[1-33]
## Concrete implementation notes
- Build a `Set<string>` of *local* type names imported from `"typeorm"` whose `imported.name` is in `typesWithConnectionProp` (so `EntityMetadata as EM` adds `EM`).
- In `collectTypedIdentifier`, match against that local-name set (instead of raw `typesWithConnectionProp`) and consider supporting `TSQualifiedName` for `import * as TypeORM from "typeorm"`.
- Update the fixture to import `EntityMetadata`/`ColumnMetadata` from `typeorm`, and add an alias fixture case (e.g. `EntityMetadata as EM`) to prevent regressions.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
I actually reported it in the constructor (because I have dynamic entities):
new EntityMetadata({ connection, ... } should be new EntityMetadata({ dataSource: connection, ... } (connection was renamed in constructor options).
new ColumnMetadata({ connection, entityMetadata, ... }) should be new ColumnMetadata({ entityMetadata, ... }) (connection was removed from constructor options, because it can be taken from entityMetadata).
But it's not really important, it's probably less effort to change those by hand than implement it in the codemod :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported by Lucian:
meta.connection.getMetadata(...)was left unchanged whenmetais typedEntityMetadata. Same forColumnMetadataandIndexMetadata.connection-to-datasourcealready renames.connection→.dataSourceon typed references toQueryRunner,EntityManager,Repository,TreeRepository,MongoRepository, and the*QueryBuilderclasses. The metadata classes were missed — their.connectionproperty was renamed to.dataSourcein #12249, same breaking change.Extends
typesWithConnectionPropwithEntityMetadata,ColumnMetadata, andIndexMetadata. Fixture gains typed-parameter cases forEntityMetadataandColumnMetadatato pin the behavior.