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
What the change is intended to do: Automatically drops dependent indices, unique constraints, and check constraints linked to database columns right before those columns are removed during schema synchronization.
Why this change is needed: Prevents database query execution errors or failures that happen when a schema synchronization tries to drop a column that still has active constraints or indices pointing to it.
How you've verified it: Inspected the code structure inside RdbmsSchemaBuilder.ts, verified the sequential execution order of schema operations, and reviewed a clean diff showing 58 target additions.
1. Misindented new schema method 📘 Rule violation⚙ Maintainability
Description
The newly added dropIndicesAndConstraintsForRemovedColumns() block is not indented like other
class methods, creating inconsistent style and likely failing formatting/lint expectations for this
file.
+/**+ * Drops indices, checks, and unique constraints that involve columns about to be dropped.+ */+protected async dropIndicesAndConstraintsForRemovedColumns(): Promise<void> {
Evidence
PR Compliance ID 4 requires avoiding inconsistent style. The new method and its comment begin at
column 0 while surrounding class methods are indented, demonstrating inconsistent formatting in the
changed code.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`dropIndicesAndConstraintsForRemovedColumns()` (and its JSDoc) is not indented consistently with the rest of `RdbmsSchemaBuilder` methods, making the style inconsistent and potentially breaking formatting/lint checks.
## Issue Context
In `src/schema-builder/RdbmsSchemaBuilder.ts`, other methods inside `export class RdbmsSchemaBuilder` are indented (e.g., `private getTablePath`). The new method starts at column 0.
## Fix Focus Areas
- src/schema-builder/RdbmsSchemaBuilder.ts[250-308]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
dropIndicesAndConstraintsForRemovedColumns() calls check.expression.includes(colName) even though
TableCheck.expression is optional, which can throw at runtime during schema sync. Substring matching
can also misidentify constraints (e.g., dropped column "id" matching "order_id"), causing unrelated
CHECK constraints to be dropped or required ones to be missed so dropRemovedColumns() still fails.
The PR introduces CHECK selection using check.expression.includes(...) without null-guarding;
TableCheck.expression is defined as optional, so this can throw. Additionally, at least Postgres
populates TableCheck.columnNames, which provides a safer way to detect referenced columns than
substring matching.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
`dropIndicesAndConstraintsForRemovedColumns()` determines which CHECK constraints reference soon-to-be-dropped columns by using `check.expression.includes(colName)`. This is unsafe because `TableCheck.expression` is optional (can be `undefined`, causing a crash), and it is logically incorrect because substring matching is not SQL-identifier aware (false positives/negatives).
### Issue Context
Several drivers (e.g., Postgres) already populate `TableCheck.columnNames`, which is a structured way to know which columns a CHECK constraint references.
### Fix Focus Areas
- src/schema-builder/RdbmsSchemaBuilder.ts[292-305]
- src/schema-builder/table/TableCheck.ts[14-37]
- src/driver/postgres/PostgresQueryRunner.ts[4218-4231]
### Suggested fix
1) Prefer structured matching:
- If `check.columnNames?.length`, drop when `check.columnNames` intersects `droppedColumnNames`.
2) Only if `columnNames` is unavailable, fall back to expression-based detection, but:
- Guard `check.expression` (skip or treat as non-match when missing)
- Use a safer identifier match (e.g., word-boundary/quoted-identifier aware regex) rather than plain substring.
This prevents crashes and avoids dropping unrelated CHECK constraints while still reliably removing those that block column drops.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
3. No tests for unique/check drops 📘 Rule violation☼ Reliability
Description
The PR adds logic to drop unique and check constraints for soon-to-be-removed columns, but there is
no corresponding functional test coverage for these new cases, increasing regression risk.
+ const uniquesToDrop = table.uniques.filter((unique) =>+ unique.columnNames.some((colName) => droppedColumnNames.includes(colName))+ )+ if (uniquesToDrop.length > 0) {+ this.dataSource.logger.logSchemaBuild(+ `dropping unique constraints from table "${table.name}" because they reference dropped columns`,+ )+ await this.queryRunner.dropUniqueConstraints(table, uniquesToDrop)
Evidence
PR Compliance ID 3 expects issue fixes to live in the functional test suite. The diff adds new
behavior for dropping unique/check constraints, while the existing related functional test asserts
only index removal when dropping a column and does not cover unique/check constraints.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
New schema sync behavior drops unique and check constraints referencing removed columns, but existing functional tests only cover dropping an index when dropping a column.
## Issue Context
`dropIndicesAndConstraintsForRemovedColumns()` now includes dropping `table.uniques` and `table.checks` when they reference columns being removed. There is an existing functional test for dropping a column with an index, but it does not assert unique/check constraint behavior.
## Fix Focus Areas
- src/schema-builder/RdbmsSchemaBuilder.ts[272-305]
- test/functional/schema-builder/column/drop/drop-column-with-index/drop-column-with-index.test.ts[23-47]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Author self-review: I have reviewed the code review findings, and addressed the relevant ones.
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.
Description of change
RdbmsSchemaBuilder.ts, verified the sequential execution order of schema operations, and reviewed a clean diff showing 58 target additions.