-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix:mysql reserved keyword issue #4106
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
Changes from 3 commits
cfcc15d
7a27084
0c03ba4
aee5fa8
8c242a4
e39d0d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |||||||||||
| # See the License for the specific language governing permissions and | ||||||||||||
| # limitations under the License. | ||||||||||||
| """Database schema version check utility.""" | ||||||||||||
|
|
||||||||||||
| from __future__ import annotations | ||||||||||||
|
|
||||||||||||
| import logging | ||||||||||||
|
|
@@ -32,8 +33,11 @@ def _get_schema_version_impl(inspector, connection) -> str: | |||||||||||
| """Gets DB schema version using inspector and connection.""" | ||||||||||||
| if inspector.has_table("adk_internal_metadata"): | ||||||||||||
| try: | ||||||||||||
| key_col = inspector.dialect.identifier_preparer.quote("key") | ||||||||||||
| result = connection.execute( | ||||||||||||
| text("SELECT value FROM adk_internal_metadata WHERE key = :key"), | ||||||||||||
| text( | ||||||||||||
| f"SELECT value FROM adk_internal_metadata WHERE {key_col} = :key" | ||||||||||||
| ), | ||||||||||||
| {"key": SCHEMA_VERSION_KEY}, | ||||||||||||
| ).fetchone() | ||||||||||||
|
Comment on lines
37
to
42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||
| if result: | ||||||||||||
|
|
@@ -48,8 +52,7 @@ def _get_schema_version_impl(inspector, connection) -> str: | |||||||||||
| "Failed to query schema version from adk_internal_metadata: %s.", | ||||||||||||
| e, | ||||||||||||
| ) | ||||||||||||
| raise | ||||||||||||
| # Metadata table doesn't exist, check for v0 schema. | ||||||||||||
| raise # Metadata table doesn't exist, check for v0 schema. | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment appears to be misplaced. It describes the logic for when the
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment Please move the comment back to its original location, on a new line after the
Suggested change
|
||||||||||||
| # V0 schema has an 'events' table with an 'actions' column. | ||||||||||||
| if inspector.has_table("events"): | ||||||||||||
| try: | ||||||||||||
|
|
||||||||||||
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.
The use of backticks (
`key`) to quote thekeycolumn is specific to MySQL and will cause syntax errors on other SQL databases like PostgreSQL. The pull request description incorrectly states that backticks are part of the SQL-92 standard and work on PostgreSQL; the standard uses double quotes. To ensure database portability, you should use a dialect-aware method for quoting identifiers. Since aninspectorobject is available,inspector.dialect.identifier_preparer.quote()can be used to get the correct quoting for the current database dialect.