Skip to content

Conversation

@rhydian0x
Copy link
Contributor

@rhydian0x rhydian0x commented Jul 2, 2025

Description of change

When using Alibaba Cloud AnalyticDB for MySQL (ADS), running SELECT VERSION() AS version returns a column named version() instead of version, which causes TypeORM to throw a TypeError in MysqlQueryRunner.getVersion().

This change updates getVersion() to support both version and version() column keys, making it compatible with ADS while keeping compatibility with standard MySQL and MariaDB.

Verified locally using ADS instance, and also tested on standard MySQL.

Related issue: #11553


Pull-Request Checklist

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

🎉 Thank you for reviewing this PR!

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility when retrieving MySQL version information, ensuring the version is correctly detected regardless of how the database returns the version string.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 2, 2025

"""

Walkthrough

The getVersion method in MysqlQueryRunner was updated to support both version and version() property keys in the query result, ensuring compatibility with AnalyticDB MySQL and similar variants. The method now checks both keys and normalizes the extracted version string, without altering any public API or method signatures.

Changes

File(s) Change Summary
src/driver/mysql/MysqlQueryRunner.ts Modified getVersion to handle query results with either version or version() property keys; improved version string extraction and normalization.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant MysqlQueryRunner
    participant MySQL/ADS DB

    App->>MysqlQueryRunner: call getVersion()
    MysqlQueryRunner->>MySQL/ADS DB: SELECT VERSION()
    MySQL/ADS DB-->>MysqlQueryRunner: returns [{version: "x.y.z"}] or [{"version()": "x.y.z"}]
    MysqlQueryRunner->>MysqlQueryRunner: Extract version from 'version' or 'version()'
    MysqlQueryRunner-->>App: Return normalized version string
Loading

Assessment against linked issues

Objective Addressed Explanation
Support getVersion() parsing for both version and version() keys in AnalyticDB MySQL (#11553)
Prevent TypeError when version property is missing in result (#11553)
Normalize and return the version string as before (#11553)

Poem

In the warren of code, a bug did appear,
"version()" or "version"?—the answer unclear!
Now rabbits can cheer, for the fix is in sight,
No more TypeErrors to give us a fright.
With paws on the keyboard and whiskers held high,
Our queries return versions—oh my!
🐇✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-07T10_00_14_272Z-debug-0.log


📜 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 77a5912 and c2c7856.

📒 Files selected for processing (1)
  • src/driver/mysql/MysqlQueryRunner.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/driver/mysql/MysqlQueryRunner.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

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

🧹 Nitpick comments (1)
src/driver/mysql/MysqlQueryRunner.ts (1)

3373-3391: Excellent implementation with minor error handling consideration.

The changes correctly address the AnalyticDB compatibility issue by supporting both column name variants. The use of nullish coalescing operator and proper TypeScript typing is well done.

However, consider adding error handling for the edge case where both version and version() properties are undefined:

 const versionString = row.version ?? row["version()"];
+
+if (!versionString) {
+    throw new TypeORMError("Unable to determine database version: neither 'version' nor 'version()' property found in query result");
+}

 return versionString.replace(/^([\d.]+).*$/, "$1")

This would prevent a potential runtime error if the query result doesn't contain either expected property.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aebc7eb and debec7c.

📒 Files selected for processing (1)
  • src/driver/mysql/MysqlQueryRunner.ts (1 hunks)

@rhydian0x
Copy link
Contributor Author

Hi @alumni , could you please help review this PR when you have time? Thanks!

@alumni alumni changed the title feat(mysql): support AnalyticDB returning version() column name in geVersion() feat(mysql): support AnalyticDB returning version() column name in getVersion() Jul 3, 2025
@rhydian0x
Copy link
Contributor Author

@alumni
Thanks! Updated the code as suggested. Please take another look when you have time 🙏

@alumni
Copy link
Collaborator

alumni commented Jul 7, 2025

@Minglu-Huo the format check will fail if I will start the workflow :) Could you fix the formatting? Thanks :)

npm run format if your editor is not set up to use prettier.

@rhydian0x
Copy link
Contributor Author

@alumni
✅ Done. I’ve run npm run format and pushed the changes.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 7, 2025

typeorm-sql-js-example

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

commit: c2c7856

@rhydian0x
Copy link
Contributor Author

Thanks @alumni for the feedback! I've updated the query to use lowercase version() as suggested to avoid the exception.

@coveralls
Copy link

Coverage Status

coverage: 76.387%. remained the same
when pulling c2c7856 on Minglu-Huo:feat/mysql-getVersion-ads
into a4c9dd8 on typeorm:master.

@alumni
Copy link
Collaborator

alumni commented Jul 7, 2025

Thanks for the fix 😀

@alumni alumni changed the title feat(mysql): support AnalyticDB returning version() column name in getVersion() fix(mysql): support AnalyticDB returning version() column name in getVersion() Jul 7, 2025
@alumni alumni requested a review from gioboa July 8, 2025 12:37
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 @Minglu-Huo 👍

@alumni alumni merged commit 1737e97 into typeorm:master Jul 8, 2025
58 checks passed
@rhydian0x
Copy link
Contributor Author

@alumni
Hi, thanks for merging the PR! I was wondering when this change will be published in a release?

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.

5 participants