Skip to content

Conversation

@ArsenyYankovsky
Copy link
Contributor

@ArsenyYankovsky ArsenyYankovsky commented Jul 14, 2025

Description of change

Fixes an issue with "regtype" being unsupported in Aurora Serverless V2 (more details here).

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change

Summary by CodeRabbit

  • Bug Fixes
    • Improved accuracy in displaying user-defined type information for columns in PostgreSQL database metadata views.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 14, 2025

Walkthrough

The SQL query in the loadTables method of PostgresQueryRunner was updated to change the casting of concatenated user-defined type schema and name from ::"regtype" to ::"regtype"::text for the "regtype" column. No other logic or public interfaces were modified.

Changes

Cohort / File(s) Change Summary
Postgres Query Metadata Cast Update
src/driver/postgres/PostgresQueryRunner.ts
Modified the SQL query in loadTables to cast concatenated type schema and name as ::"regtype"::text instead of ::"regtype" for the "regtype" column. No other logic was changed.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A hop and a skip, a cast to text,
In columns deep, the query's next.
No logic changed, just tidy and neat,
With PostgreSQL, the code's complete.
A bunny approves, with whiskers curled—
Small changes make a smoother world! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8f7acb and 8f06165.

📒 Files selected for processing (1)
  • src/driver/postgres/PostgresQueryRunner.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/driver/postgres/PostgresQueryRunner.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: tests-linux (20) / mysql_mariadb
  • GitHub Check: tests-linux (20) / sqlite
  • GitHub Check: tests-linux (20) / mssql
  • GitHub Check: tests-linux (20) / mongodb
  • GitHub Check: tests-linux (20) / cockroachdb
  • GitHub Check: tests-linux (20) / sqljs
  • GitHub Check: tests-linux (20) / better-sqlite3
  • GitHub Check: tests-linux (18) / mongodb
  • GitHub Check: tests-linux (18) / mssql
  • GitHub Check: tests-linux (18) / sqljs
  • GitHub Check: tests-linux (18) / better-sqlite3
  • GitHub Check: tests-linux (18) / postgres (17-3.5)
  • GitHub Check: tests-linux (18) / postgres (14-3.5)
  • GitHub Check: tests-linux (18) / mysql_mariadb
  • GitHub Check: tests-linux (18) / sqlite
  • GitHub Check: tests-windows / sqljs
  • GitHub Check: tests-windows / sqlite
  • GitHub Check: tests-windows / better-sqlite3
  • GitHub Check: Analyze (javascript-typescript)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 14, 2025

typeorm-sql-js-example

npm i https://pkg.pr.new/typeorm/typeorm@11568

commit: 8f06165

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts (2)

755-756: Use optional chaining for cleaner code.

Apply this diff to use optional chaining:

-if (results[0] && results[0].value) {
-    tableColumn.asExpression = results[0].value
+if (results[0]?.value) {
+    tableColumn.asExpression = results[0].value

496-523: Consider batching queries to improve performance.

The method executes individual queries for each column when checking for user-defined types and spatial features. For databases with many columns, this could lead to performance issues.

Consider batching these queries or fetching all necessary metadata upfront to reduce the number of database round trips.

Also applies to: 550-561

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f351757 and 73a364b.

📒 Files selected for processing (2)
  • src/driver/aurora-postgres/AuroraPostgresConnectionOptions.ts (1 hunks)
  • src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts

[error] 755-755: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: tests-linux (20) / sap
  • GitHub Check: tests-linux (20) / better-sqlite3
  • GitHub Check: tests-linux (20) / mysql_mariadb
  • GitHub Check: tests-linux (20) / oracle
  • GitHub Check: tests-linux (18) / sap
  • GitHub Check: tests-linux (18) / mssql
  • GitHub Check: tests-linux (18) / oracle
  • GitHub Check: tests-linux (20) / mongodb
  • GitHub Check: tests-linux (20) / cockroachdb
  • GitHub Check: tests-linux (18) / postgres (14-3.5)
  • GitHub Check: tests-linux (18) / sqlite
  • GitHub Check: tests-linux (18) / mongodb
  • GitHub Check: tests-linux (18) / better-sqlite3
  • GitHub Check: tests-linux (18) / sqljs
  • GitHub Check: tests-linux (18) / postgres (17-3.5)
  • GitHub Check: tests-linux (18) / mysql_mariadb
  • GitHub Check: tests-windows / sqljs
  • GitHub Check: tests-windows / better-sqlite3
  • GitHub Check: tests-windows / sqlite
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
src/driver/aurora-postgres/AuroraPostgresConnectionOptions.ts (1)

47-47: LGTM!

The addition of the optional schema property is appropriate and maintains backward compatibility.

src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts (1)

274-274: Good handling of the regtype compatibility issue.

The implementation properly addresses the "regtype is not supported in aurora serverless v2" issue by using an alias in the SQL query and retrieving the type information correctly.

Also applies to: 408-408

@coveralls
Copy link

coveralls commented Jul 14, 2025

Coverage Status

coverage: 76.353% (-0.09%) from 76.44%
when pulling 8f06165 on ArsenyYankovsky:master
into f351757 on typeorm:master.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (4)
src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts (4)

245-248: Use parameterized queries or escape literals to prevent SQL injection.

The schema and tableName values are directly concatenated into SQL strings without proper escaping, creating a SQL injection vulnerability.

Use parameterized queries or escape the values:

-return `("table_schema" = '${schema || currentSchema}' AND "table_name" = '${tableName}')`
+return `("table_schema" = $1 AND "table_name" = $2)`

And pass the values as parameters, or use the escape method:

-return `("table_schema" = '${schema || currentSchema}' AND "table_name" = '${tableName}')`
+return `("table_schema" = ${this.escape(schema || currentSchema)} AND "table_name" = ${this.escape(tableName)})`

268-270: Use parameterized queries or escape literals to prevent SQL injection.

Same SQL injection vulnerability as above - direct string concatenation without proper escaping.

Apply the same fix as suggested for the table filtering above.


353-358: Add error handling for database queries.

The database queries lack proper error handling, which can cause unhandled exceptions and make debugging difficult.

Wrap the queries in try-catch blocks:

-const [
-    dbColumns,
-    dbConstraints,
-    dbIndices,
-    dbForeignKeys,
-]: ObjectLiteral[][] = await Promise.all([
-    this.query(columnsSql),
-    this.query(constraintsSql),
-    this.query(indicesSql),
-    this.query(foreignKeysSql),
-])
+let dbColumns: ObjectLiteral[], dbConstraints: ObjectLiteral[], 
+    dbIndices: ObjectLiteral[], dbForeignKeys: ObjectLiteral[];
+
+try {
+    [dbColumns, dbConstraints, dbIndices, dbForeignKeys] = await Promise.all([
+        this.query(columnsSql),
+        this.query(constraintsSql),
+        this.query(indicesSql),
+        this.query(foreignKeysSql),
+    ]);
+} catch (error) {
+    throw new TypeORMError(`Failed to load table metadata: ${error.message}`);
+}

220-943: Refactor this large method into smaller, focused methods.

This method is over 720 lines long and handles multiple responsibilities, significantly impacting readability and maintainability.

Break it down into smaller methods such as:

  • loadTableMetadata()
  • loadColumnMetadata()
  • loadConstraintMetadata()
  • loadIndexMetadata()
  • loadForeignKeyMetadata()
  • buildTableFromMetadata()
🧹 Nitpick comments (1)
src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts (1)

755-755: Use optional chaining for cleaner code.

The condition can be simplified using optional chaining.

-if (results[0] && results[0].value) {
+if (results[0]?.value) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73a364b and 2b4fd8e.

📒 Files selected for processing (1)
  • src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts (6)
src/schema-builder/table/Table.ts (1)
  • Table (15-427)
src/schema-builder/table/TableColumn.ts (1)
  • TableColumn (6-228)
src/util/OrmUtils.ts (1)
  • OrmUtils (8-588)
src/schema-builder/table/TableUnique.ts (1)
  • TableUnique (7-71)
src/schema-builder/table/TableForeignKey.ts (1)
  • TableForeignKey (8-123)
src/schema-builder/table/TableIndex.ts (1)
  • TableIndex (7-126)
🪛 Biome (1.9.4)
src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts

[error] 755-755: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (5)
src/driver/aurora-postgres/AuroraPostgresQueryRunner.ts (5)

11-21: LGTM! Imports are appropriate for the new functionality.

The imported classes and utilities are all necessary for the table metadata loading functionality being added.


220-230: LGTM! Method signature and initial setup are well-structured.

The method properly handles edge cases with early returns and sets up necessary context variables.


408-408: LGTM! Core fix for Aurora Serverless V2 regtype compatibility.

Using regtype from the query results properly addresses the Aurora Serverless V2 compatibility issue mentioned in the PR objectives.


410-600: LGTM! Comprehensive column processing logic.

The column processing handles various PostgreSQL-specific features including numeric precision/scale, time precision, user-defined types, enums, spatial types, and length properties. The implementation is thorough and well-structured.


775-938: LGTM! Well-structured constraint processing logic.

The constraint processing comprehensively handles unique, check, exclusion, foreign key, and index constraints. The use of OrmUtils.uniq for grouping and the mapping to appropriate Table classes is well-implemented.

Copy link
Collaborator

@alumni alumni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do it like this, the Aurora driver will not benefit from the future updates we plan to do to the Postgres driver.

Would be great if you could make it work in the PostgresQueryRunner by finding a solution that works on all platforms, instead of copy-pasting the loadTables method and changing 2 lines.

@ArsenyYankovsky
Copy link
Contributor Author

Fair enough, I changed the type of the column in the parent class (it's used as a string) which works for both Aurora and regular Postgres.

@ArsenyYankovsky
Copy link
Contributor Author

I see the tests are failing, will check later this week.

@ArsenyYankovsky
Copy link
Contributor Author

Should be good now.

@ArsenyYankovsky ArsenyYankovsky requested a review from alumni August 4, 2025 21:33
Copy link
Collaborator

@alumni alumni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thanks! 👏🏻

Copy link
Collaborator

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help @ArsenyYankovsky

@gioboa gioboa merged commit 6e9f20d into typeorm:master Aug 5, 2025
58 checks passed
ThbltLmr pushed a commit to ThbltLmr/typeorm that referenced this pull request Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants