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
Replaces Promise.all patterns that fire multiple queries concurrently on the same pg client connection with sequential execution. pg 8.19.0 deprecated calling client.query() while the client is already executing a query, and this will become a hard error in pg 9.0.
Affected methods in both PostgresQueryRunner and CockroachQueryRunner:
Execute database queries sequentially to avoid pg deprecation
🐞 Bug fix
Walkthroughs
Description
• Replace concurrent Promise.all query patterns with sequential execution
• Avoid pg 8.19.0 deprecation warning for concurrent queries on same connection
• Affected methods: loadTables(), clearDatabase(), dropEnumTypes()
• Applied to both PostgresQueryRunner and CockroachQueryRunner classes
Diagram
flowchart LR
A["Promise.all concurrent queries"] -->|"Replace with"| B["Sequential for-loop execution"]
B -->|"Prevents"| C["pg 8.19.0 deprecation warning"]
C -->|"Avoids"| D["pg 9.0 hard error"]
• Replaced Promise.all with sequential for loops in clearDatabase() method for dropping views,
materialized views, and tables
• Converted parallel metadata queries in loadTables() to sequential execution for columns,
constraints, indices, and foreign keys
• Updated dropEnumTypes() to execute DROP TYPE statements sequentially instead of concurrently
• Replaced Promise.all with sequential for loops in clearDatabase() method for dropping views,
tables, and sequences
• Converted parallel metadata queries in loadTables() to sequential execution for columns,
constraints, indices, foreign keys, and enums
• Updated dropEnumTypes() to execute DROP TYPE statements sequentially instead of concurrently
1. Postgres loadTables still concurrent 🐞 Bug⛯ Reliability
Description
PostgresQueryRunner.loadTables() still returns Promise.all(dbTables.map(...)) while the
per-table/per-column mapping performs additional await this.query(...) calls (e.g., enum and
spatial metadata lookups). Because connect() caches a single databaseConnection per query
runner, those queries can overlap and still trigger the pg concurrent-query deprecation/hard error.
The query runner holds onto a single pooled connection (this.databaseConnection) and query()
executes against it; therefore, concurrent this.query() calls from Promise.all(...) can overlap
on the same client connection. In loadTables(), even after making the initial metadata queries
sequential, the code still processes tables/columns via Promise.all(...) and performs further
this.query() calls inside those async callbacks (enum and geometry/geography lookups), which
reintroduces concurrent queries.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`PostgresQueryRunner.loadTables()` still issues additional database queries inside async callbacks executed via `Promise.all(...)`. Since PostgresQueryRunner caches a single pg connection per query runner, concurrent `this.query()` calls can overlap and still trigger the pg 8.19 deprecation warning / pg 9 hard error.
### Issue Context
- `connect()` caches `this.databaseConnection`.
- `query()` always executes against that cached connection.
- `loadTables()` uses `Promise.all(dbTables.map(async ...))` and `Promise.all(...map(async dbColumn => ... await this.query(...)))`, which can interleave.
### Fix Focus Areas
- src/driver/postgres/PostgresQueryRunner.ts[3616-3645]
- src/driver/postgres/PostgresQueryRunner.ts[3785-3835]
### Suggested fix approach
Choose one:
1) **Local sequencing in `loadTables()`**
- Replace `return Promise.all(dbTables.map(...))` with a sequential `for...of` that pushes built `Table` objects into an array.
- Replace `table.columns = await Promise.all(...map(async ...))` with a `for...of` loop that builds columns sequentially **at least for branches that call `this.query()`** (enum/spatial/user-defined lookups).
2) **Global sequencing in `query()` (more robust)**
- Add a private promise-chain/lock on the query runner (e.g., `private queryQueue = Promise.resolve()`), and wrap the actual `databaseConnection.query(...)` execution so each call waits for the previous to finish.
- Ensure the queue advances even when a query throws (use `finally`).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. Postgres constraints still concurrent 🐞 Bug⛯ Reliability
Description
PostgresQueryRunner still executes some DDL operations concurrently via Promise.all (check +
exclusion constraints). Since the query runner uses a single cached pg client connection, these
methods can still issue overlapping client.query() calls and continue to hit the pg 8.19+
deprecation (pg 9.0 error).
The PR is making queries sequential in loadTables, but
createCheckConstraints/dropCheckConstraints and
createExclusionConstraints/dropExclusionConstraints still use Promise.all, which can run
multiple executeQueries() calls at once. executeQueries() calls this.query() internally, and
query() uses the single cached databaseConnection from connect() and calls
databaseConnection.query(...) directly—so overlapping promises can overlap pg client queries on
the same connection.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`PostgresQueryRunner` still has several methods that run multiple DDL operations concurrently using `Promise.all(...)`. Because a QueryRunner caches a single pg client connection and `executeQueries()` ultimately calls `databaseConnection.query(...)`, these `Promise.all` blocks can still overlap `client.query()` calls on the same connection, defeating the PR’s goal (pg 8.19 deprecation / pg 9 error).
### Issue Context
This PR already sequentializes queries in `loadTables`, `clearDatabase`, and `dropEnumTypes`. For completeness (and to ensure the deprecation is avoided across common schema/migration flows), update the remaining constraint helpers to be sequential as well.
### Fix Focus Areas
- src/driver/postgres/PostgresQueryRunner.ts[2901-2909]
- src/driver/postgres/PostgresQueryRunner.ts[2942-2950]
- src/driver/postgres/PostgresQueryRunner.ts[2984-2992]
- src/driver/postgres/PostgresQueryRunner.ts[3030-3038]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
3. Cockroach loadTables still concurrent 🐞 Bug⛯ Reliability
Description
CockroachQueryRunner.loadTables() still returns Promise.all(dbTables.map(...)) while the
per-column mapping performs extra await this.query(...) calls (generated column expression and
spatial metadata). Since the query runner caches a single connection, these can overlap and still
violate the “no concurrent queries per client” requirement.
Like the Postgres runner, CockroachQueryRunner caches a single databaseConnection and query()
executes against it. loadTables() still uses Promise.all(dbTables.map(...)) and builds columns
with Promise.all(...), but inside those callbacks it runs additional this.query() calls
(generated columns metadata, spatial metadata). This can still cause overlapping
databaseConnection.query(...) calls on a single connection.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`CockroachQueryRunner.loadTables()` still performs `this.query()` inside async callbacks executed via `Promise.all(...)`. Because CockroachQueryRunner caches a single connection per query runner, this can still create concurrent `databaseConnection.query(...)` calls.
### Issue Context
- `connect()` caches `this.databaseConnection`.
- `query()` executes on that cached connection.
- `loadTables()` uses `Promise.all(dbTables.map(...))` and `Promise.all` for columns while calling `this.query()` for generated column expressions and spatial metadata.
### Fix Focus Areas
- src/driver/cockroachdb/CockroachQueryRunner.ts[3173-3203]
- src/driver/cockroachdb/CockroachQueryRunner.ts[3495-3506]
- src/driver/cockroachdb/CockroachQueryRunner.ts[3522-3538]
### Suggested fix approach
Choose one:
1) **Local sequencing in `loadTables()`**
- Replace `return Promise.all(dbTables.map(...))` with a `for...of` loop assembling `Table[]`.
- Replace `table.columns = await Promise.all(...)` with sequential column construction when branches may execute `this.query()`.
2) **Global sequencing in `query()`**
- Add a per-query-runner queue/lock so even if callers use `Promise.all`, actual wire queries are executed sequentially.
- Ensure errors don’t break the queue (advance in `finally`).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
View more (1) 4. Postgres constraints still concurrent 🐞 Bug⛯ Reliability
Description
PostgresQueryRunner still executes some DDL operations concurrently via Promise.all (check +
exclusion constraints). Since the query runner uses a single cached pg client connection, these
methods can still issue overlapping client.query() calls and continue to hit the pg 8.19+
deprecation (pg 9.0 error).
The PR is making queries sequential in loadTables, but
createCheckConstraints/dropCheckConstraints and
createExclusionConstraints/dropExclusionConstraints still use Promise.all, which can run
multiple executeQueries() calls at once. executeQueries() calls this.query() internally, and
query() uses the single cached databaseConnection from connect() and calls
databaseConnection.query(...) directly—so overlapping promises can overlap pg client queries on
the same connection.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`PostgresQueryRunner` still has several methods that run multiple DDL operations concurrently using `Promise.all(...)`. Because a QueryRunner caches a single pg client connection and `executeQueries()` ultimately calls `databaseConnection.query(...)`, these `Promise.all` blocks can still overlap `client.query()` calls on the same connection, defeating the PR’s goal (pg 8.19 deprecation / pg 9 error).
### Issue Context
This PR already sequentializes queries in `loadTables`, `clearDatabase`, and `dropEnumTypes`. For completeness (and to ensure the deprecation is avoided across common schema/migration flows), update the remaining constraint helpers to be sequential as well.
### Fix Focus Areas
- src/driver/postgres/PostgresQueryRunner.ts[2901-2909]
- src/driver/postgres/PostgresQueryRunner.ts[2942-2950]
- src/driver/postgres/PostgresQueryRunner.ts[2984-2992]
- src/driver/postgres/PostgresQueryRunner.ts[3030-3038]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
5. No functional regression test 📘 Rule violation⛯ Reliability
Description
This PR fixes an issue caused by concurrent client.query() calls but does not add/update a
functional test to prevent regressions. Without coverage, future refactors could reintroduce the
deprecated concurrent query pattern.
The checklist expects issue fixes to be covered by functional tests; the PR description indicates
this is an issue fix for concurrent query deprecation, while the changed code shows the behavior
change but no accompanying functional test update is present in the provided PR diff.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
This PR changes Postgres/Cockroach query execution order to avoid concurrent `client.query()` calls, but it does not add/update a functional test to guard against regressions.
## Issue Context
The PR is explicitly an issue fix for pg 8.19.0 concurrent query deprecation (future hard error in pg 9.0). The fix should be backed by a functional test that exercises the affected QueryRunner paths (e.g., metadata loading via `getTable()` / schema introspection) so concurrency regressions are caught.
## Fix Focus Areas
- src/driver/postgres/PostgresQueryRunner.ts[3616-3619]
- test/functional/query-runner/drop-table.test.ts[10-77]ান
ⓘ 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
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.
Replaces
Promise.allpatterns that fire multiple queries concurrently on the same pg client connection with sequential execution. pg 8.19.0 deprecated callingclient.query()while the client is already executing a query, and this will become a hard error in pg 9.0.Affected methods in both
PostgresQueryRunnerandCockroachQueryRunner:loadTables()— parallel metadata queries (columns, constraints, indices, foreign keys)clearDatabase()— parallel DROP statements for views, materialized views, tables, sequencesdropEnumTypes()— parallel DROP TYPE statementsCloses #12055