-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix: regtype is not supported in aurora serverless v2 #11568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe SQL query in the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
commit: |
There was a problem hiding this 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
📒 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
schemaproperty 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
There was a problem hiding this 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
📒 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
regtypefrom 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.uniqfor grouping and the mapping to appropriate Table classes is well-implemented.
alumni
left a comment
There was a problem hiding this 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.
|
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. |
|
I see the tests are failing, will check later this week. |
|
Should be good now. |
alumni
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks! 👏🏻
gioboa
left a comment
There was a problem hiding this 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
Description of change
Fixes an issue with "regtype" being unsupported in Aurora Serverless V2 (more details here).
Pull-Request Checklist
masterbranchFixes #00000Summary by CodeRabbit