Skip to content

Conversation

@glasnt
Copy link
Contributor

@glasnt glasnt commented Mar 31, 2025

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@product-auto-label product-auto-label bot added api: cloudsql Issues related to the Cloud SQL for MySQL API. samples Issues that are directly related to samples. asset: pattern DEE Asset tagging - Pattern. labels Mar 31, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @glasnt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request migrates the MySQL and PostgreSQL samples to the new CI (Continuous Integration) setup. This involves updating the CI configuration files and modifying the test scripts to align with the new CI environment. Specifically, the changes include adding new CI setup files for MySQL and PostgreSQL, updating the nodejs-dev.jsonc file to include the new samples, and removing the samples from the nodejs-prod.jsonc file. Additionally, the index.js file for MySQL is modified to use the connect-connector-auto-iam-authn.js file, and the package.json file for PostgreSQL is updated to include a proxy script and modify the test script.

Highlights

  • CI Migration: The primary goal is to migrate the MySQL and PostgreSQL samples to the new CI environment.
  • Configuration Updates: The .github/config/nodejs-dev.jsonc and .github/config/nodejs-prod.jsonc files are updated to reflect the new CI setup.
  • Test Script Modification: The test script in cloud-sql/postgres/knex/package.json is modified to include a proxy command.
  • New CI Setup Files: New ci-setup.json files are added for both MySQL and PostgreSQL samples.

Changelog

Click here to see the changelog
  • .github/config/nodejs-dev.jsonc
    • Added cloud-sql/mysql/mysql2 and cloud-sql/postgres/knex to the list of samples to be tested in the development CI.
  • .github/config/nodejs-prod.jsonc
    • Removed cloud-sql/mysql/mysql2 and cloud-sql/postgres/knex from the list of samples to be tested in the production CI. This likely means they are now passing tests and no longer need to be excluded.
  • cloud-sql/mysql/mysql2/ci-setup.json
    • Added a new file ci-setup.json to configure the CI environment for the MySQL sample using mysql2.
    • The file defines environment variables such as INSTANCE_HOST, INSTANCE_CONNECTION_NAME, UNIX_SOCKET_DIR, CLOUD_SQL_CONNECTION_NAME, INSTANCE_UNIX_SOCKET, DB_NAME, and DB_USER.
    • It also defines a secret for DB_PASS.
  • cloud-sql/mysql/mysql2/index.js
    • Modified the index.js file to use connect-connector-auto-iam-authn.js instead of connect-connector-with-iam-authn.js. This likely simplifies the IAM authentication process.
  • cloud-sql/postgres/knex/ci-setup.json
    • Added a new file ci-setup.json to configure the CI environment for the PostgreSQL sample using knex.
    • The file defines environment variables such as INSTANCE_HOST, INSTANCE_CONNECTION_NAME, UNIX_SOCKET_DIR, CLOUD_SQL_CONNECTION_NAME, INSTANCE_UNIX_SOCKET, DB_NAME, and DB_USER.
    • It also defines a secret for DB_PASS.
  • cloud-sql/postgres/knex/package.json
    • Added a proxy script that executes sql-proxy.sh.
    • Modified the test script to run the proxy script before executing the tests. This ensures that the Cloud SQL proxy is running before the tests start.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Trivia time!

What is Knex.js and what database systems does it support?

Click here for the answer
Knex.js is a "batteries included" SQL query builder for Javascript. It supports PostgreSQL, MySQL, SQLite3, MariaDB, Oracle, and MSSQL.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request migrates MySQL and PostgreSQL samples to a new CI. The changes involve updating configuration files and modifying code to use the Cloud SQL Node.js Connector. Overall, the changes seem reasonable, but there are a few areas that could be improved.

Summary of Findings

  • Missing Error Handling: The proxy script in package.json for the PostgreSQL sample does not include error handling. If the script fails, the tests will not run correctly, leading to false positives or failures.
  • Inconsistent Naming: In cloud-sql/mysql/mysql2/index.js, the createConnectorIAMAuthnPool function is being assigned a file path that contains auto in the name, but in cloud-sql/postgres/knex/index.js it is not. This could lead to confusion.

Merge Readiness

The pull request is almost ready for merging, but there are a few issues that need to be addressed. Specifically, the missing error handling in the proxy script for the PostgreSQL sample should be fixed. Additionally, the naming inconsistency in the createConnectorIAMAuthnPool function assignment should be addressed for clarity. I am unable to approve this pull request, and recommend that another reviewer does so after these changes are made.

@glasnt glasnt self-assigned this Apr 1, 2025
@glasnt
Copy link
Contributor Author

glasnt commented Apr 1, 2025

The MySQL2 sample was failing for reasons unrelated to the migration:

  • acquireTimeout: Ignoring invalid configuration option passed to Connection: acquireTimeout. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection
  • results issues: According to https://sidorares.github.io/node-mysql2/docs#first-query the result is [results, fields], which means we need to drop the fields before processing. This is a different format to other drivers, so this will be a difference in largely identical samples.

@glasnt
Copy link
Contributor Author

glasnt commented Apr 1, 2025

mysql/mysql2 was introduced in #3264 but that commit never contributed a test/server-unix.test.js file, nor even referenced presumably a test/server-tcp.test.js, no idea how npm run test ever passed because the system-test-tcp and system-test-unix targets reference files that never existed.

@glasnt glasnt marked this pull request as ready for review April 1, 2025 05:05
@glasnt glasnt requested review from a team as code owners April 1, 2025 05:05
@snippet-bot
Copy link

snippet-bot bot commented Apr 1, 2025

No region tags are edited in this PR.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@glasnt glasnt dismissed gemini-code-assist[bot]’s stale review April 1, 2025 05:07

bot can't resolve requested changes

Copy link
Contributor

@jackwotherspoon jackwotherspoon left a comment

Choose a reason for hiding this comment

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

Thanks @glasnt 👍

@glasnt glasnt merged commit e96838c into main Apr 1, 2025
13 checks passed
@glasnt glasnt deleted the sql-custard branch April 1, 2025 21:21
rudrakhsha-crest pushed a commit to rudrakhsha-crest/nodejs-docs-samples that referenced this pull request Apr 18, 2025
…oudPlatform#4055)

* chore(cloud-sql): migrate mysql, postgres samples to new CI

* rename to match postgres version

* acquireTimeout warns in mysql2, remove

* mysql2 query returns [results, fields], so only return fields

* remove unused test scripts

* revert bot-suggested rename: would cause excessive region tag change
rudrakhsha-crest added a commit to rudrakhsha-crest/nodejs-docs-samples that referenced this pull request Apr 18, 2025
…oudPlatform#4055)

* chore(cloud-sql): migrate mysql, postgres samples to new CI

* rename to match postgres version

* acquireTimeout warns in mysql2, remove

* mysql2 query returns [results, fields], so only return fields

* remove unused test scripts

* revert bot-suggested rename: would cause excessive region tag change
rudrakhsha-crest added a commit to rudrakhsha-crest/nodejs-docs-samples that referenced this pull request Apr 18, 2025
…oudPlatform#4055)

* chore(cloud-sql): migrate mysql, postgres samples to new CI

* rename to match postgres version

* acquireTimeout warns in mysql2, remove

* mysql2 query returns [results, fields], so only return fields

* remove unused test scripts

* revert bot-suggested rename: would cause excessive region tag change
rudrakhsha-crest pushed a commit to rudrakhsha-crest/nodejs-docs-samples that referenced this pull request Apr 18, 2025
…oudPlatform#4055)

* chore(cloud-sql): migrate mysql, postgres samples to new CI

* rename to match postgres version

* acquireTimeout warns in mysql2, remove

* mysql2 query returns [results, fields], so only return fields

* remove unused test scripts

* revert bot-suggested rename: would cause excessive region tag change
utsav1810 pushed a commit that referenced this pull request May 19, 2025
* Added CRUD code snippets with codeowners file

* Solved linting errors

* Added sanitization code snippets along with test cases

* Added header comment

* Removed hardcoded value from test file

* Removed crud related files

* Addressed gemini bot comments

* Updated prompts, tests and log statements for sanitization APIs

* chore(cloud-sql): migrate mysql, postgres samples to new CI (#4055)

* chore(cloud-sql): migrate mysql, postgres samples to new CI

* rename to match postgres version

* acquireTimeout warns in mysql2, remove

* mysql2 query returns [results, fields], so only return fields

* remove unused test scripts

* revert bot-suggested rename: would cause excessive region tag change

* chore(compute): Migrate region tag (#4047)

* chore(compute): Migrate region tag

* chore(compute): Rename region tag

* chore(compute): Renove older region tag (#4062)

overriding failure as this is jsut removing the region tag.

* feat: support testing on forked repos (#4057)

* feat: support testing on forked repos

* add pull_request to test on PR

* remove prod suffix

* decode json on matrix paths

* add experimental to check names

* add experimental to job names

* run test only if paths is not empty

* test explicitly against empty array

* move experimental as a prefix

* success check if no paths are found

* always set check to done

* remove pull_request trigger

* rearrange if check

* add more comments

* fix: add id-token to workflows (#4063)

* feat: support testing on forked repos

* add pull_request to test on PR

* remove prod suffix

* decode json on matrix paths

* add experimental to check names

* add experimental to job names

* run test only if paths is not empty

* test explicitly against empty array

* move experimental as a prefix

* success check if no paths are found

* always set check to done

* remove pull_request trigger

* rearrange if check

* add more comments

* fix: add id-token to workflows

* chore: update the minimum language based on maintenance mode

* chore(deps): pin dependencies (#4035)

* Added region tags to snippets

* Updated region tags for code snippets based on errors

* Removed extra csam assertions in sanitization tests

* Addressed review comments

* Updated test cases for sanitization snippets, added test for rai filter

* Updated tests as per review comments

* updated commented variables sample values in code snippets

* Addressed review comments and updated tests accordingly

* removed-todo-developer-comments

* add-new-line-eslintrc

* fix-linting-warnings-and-errors

* fixed-tests

* revert-security-center-change

* revert-security-center-change

* revert-security-center-change

* fix-minor-lint

---------

Co-authored-by: Eric Schmidt <[email protected]>
Co-authored-by: Harsh Nasit <[email protected]>
Co-authored-by: harshnasitcrest <[email protected]>
Co-authored-by: David Cavazos <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: cloudsql Issues related to the Cloud SQL for MySQL API. asset: pattern DEE Asset tagging - Pattern. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants