You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: add support for table comments in SAP HANA - #11939
This pull request links relevant issues as Fixes #10621
There are new or updated tests validating the change (tests/**.test.ts)
Documentation has been updated to reflect this change (docs/docs/**.md)
PR Type
Enhancement
Description
Implement changeTableComment method for SAP HANA driver
Fix variable naming and state management in MySQL and Postgres drivers
Add table comment loading from SAP HANA system tables
Add comprehensive tests for table comments across all supported drivers
Diagram Walkthrough
flowchart LR
A["SAP HANA Driver"] -->|implement changeTableComment| B["Table Comment Support"]
C["MySQL Driver"] -->|fix variable naming| B
D["Postgres Driver"] -->|fix variable naming| B
E["Schema Builder"] -->|enable SAP support| B
F["System Tables"] -->|load COMMENTS field| B
B -->|test coverage| G["Functional Tests"]
Loading
File Walkthrough
Relevant files
Enhancement
SapQueryRunner.ts
Implement table and column comment support for SAP
src/driver/sap/SapQueryRunner.ts
Implement changeTableComment method to replace error-throwing stub
Add table comment loading from SYS.TABLES.COMMENTS in loadTables method
Add column comment support in addColumn method
Add table comment assignment in table metadata initialization
In the test file, avoid hardcoding the schema name to 'SYSTEM'. Instead, dynamically retrieve the current schema to make the tests more robust and environment-independent.
+const [{ schema }] = await dataSource.query(+ `SELECT CURRENT_SCHEMA AS "schema" FROM "SYS"."DUMMY"`,+)
const res = await dataSource.query(
- `SELECT "COMMENTS" FROM "SYS"."TABLES" WHERE "TABLE_NAME" = ? AND "SCHEMA_NAME" = 'SYSTEM'`,- [tableName],+ `SELECT "COMMENTS" FROM "SYS"."TABLES" WHERE "TABLE_NAME" = ? AND "SCHEMA_NAME" = ?`,+ [tableName, schema],
)
return res.length > 0 ? res[0]["COMMENTS"] : undefined
Apply / Chat
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies that hardcoding the schema name 'SYSTEM' in tests can lead to failures in environments with different configurations, and proposes a robust solution to dynamically determine the schema.
Medium
Avoid invalid CREATE TABLE syntax
Verify that CREATE TABLE ... COMMENT '...' is supported on all target SAP HANA versions. If not, use a separate COMMENT ON TABLE ... query for better compatibility.
Why: This suggestion raises a valid compatibility concern about CREATE TABLE ... COMMENT syntax across different SAP HANA versions, proposing a more portable COMMENT ON TABLE query which is a safer approach.
Medium
General
Normalize empty comments consistently
When loading table metadata, normalize null or empty string comments from the database to undefined. This prevents incorrect comparisons and unnecessary ALTER TABLE statements during schema synchronization.
Why: This suggestion correctly points out a potential issue with how empty comments are handled, which could lead to unnecessary database operations. Normalizing null or empty strings to undefined improves consistency and prevents incorrect diffs during synchronization.
To prevent a potential SQL injection vulnerability, refactor the query construction in loadTables to use parameterized queries instead of directly interpolating table and schema names into the SQL string.
const dbTables: {
SCHEMA_NAME: string
TABLE_NAME: string
COMMENTS: string
}[] = []
if (!tableNames) {
const tablesSql = `SELECT "SCHEMA_NAME", "TABLE_NAME", "COMMENTS" FROM "SYS"."TABLES"`
-
dbTables.push(...(await this.query(tablesSql)))
} else {
- const tablesCondition = tableNames- .map((tableName) => {- let [schema, name] = tableName.split(".")- if (!name) {- name = schema- schema = this.driver.options.schema || currentSchema- }- return `("SCHEMA_NAME" = '${schema}' AND "TABLE_NAME" = '${name}')`- })- .join(" OR ")-- const tablesSql =- `SELECT "SCHEMA_NAME", "TABLE_NAME", "COMMENTS" FROM "SYS"."TABLES" WHERE ` +- tablesCondition-- dbTables.push(...(await this.query(tablesSql)))+ const conditions = tableNames.map((tableName) => {+ let [schema, name] = tableName.split(".")+ if (!name) {+ name = schema+ schema = this.driver.options.schema || currentSchema+ }+ return { schema, name }+ })++ const placeholders = conditions.map(() => `("SCHEMA_NAME" = ? AND "TABLE_NAME" = ?)`).join(" OR ")+ const parameters = conditions.flatMap(c => [c.schema, c.name])++ const tablesSql = `SELECT "SCHEMA_NAME", "TABLE_NAME", "COMMENTS" FROM "SYS"."TABLES" WHERE ${placeholders}`+ dbTables.push(...(await this.query(tablesSql, parameters)))
}
Suggestion importance[1-10]: 10
__
Why: The suggestion correctly identifies a critical SQL injection vulnerability in the loadTables method and provides a valid fix using parameterized queries, which is a best practice for database security.
Fix a SQL injection vulnerability in the loadTables method by using parameterized queries instead of directly interpolating table and schema names into the SQL string.
const dbTables: {
SCHEMA_NAME: string
TABLE_NAME: string
COMMENTS: string
}[] = []
if (!tableNames) {
const tablesSql = `SELECT "SCHEMA_NAME", "TABLE_NAME", "COMMENTS" FROM "SYS"."TABLES"`
dbTables.push(...(await this.query(tablesSql)))
} else {
- const tablesCondition = tableNames- .map((tableName) => {- let [schema, name] = tableName.split(".")- if (!name) {- name = schema- schema = this.driver.options.schema || currentSchema- }- return `("SCHEMA_NAME" = '${schema}' AND "TABLE_NAME" = '${name}')`- })- .join(" OR ")+ const conditions: string[] = []+ const parameters: any[] = []++ tableNames.forEach((tableName) => {+ let [schema, name] = tableName.split(".")+ if (!name) {+ name = schema+ schema = this.driver.options.schema || currentSchema+ }+ conditions.push(`("SCHEMA_NAME" = ? AND "TABLE_NAME" = ?)`)+ parameters.push(schema, name)+ })
const tablesSql =
`SELECT "SCHEMA_NAME", "TABLE_NAME", "COMMENTS" FROM "SYS"."TABLES" WHERE ` +
- tablesCondition+ conditions.join(" OR ")- dbTables.push(...(await this.query(tablesSql)))+ dbTables.push(...(await this.query(tablesSql, parameters)))
}
Suggestion importance[1-10]: 10
__
Why: The suggestion correctly identifies a critical SQL injection vulnerability in the loadTables method and provides a secure fix using parameterized queries, which is the standard best practice.
✅ Remove redundant comment down querySuggestion Impact:The suggestion was directly implemented. The commit removed the redundant downQuery block (lines 198-211) that was setting the column comment to NULL in the addColumn method, exactly as suggested.
code diff:
- if (column.comment) {- upQueries.push(- new Query(- `COMMENT ON COLUMN ${this.escapePath(table)}."${column.name}"- IS ${this.escapeComment(column.comment)}`,- ),- )- downQueries.push(- new Query(- `COMMENT ON COLUMN ${this.escapePath(table)}."${column.name}"- IS NULL`,- ),- )- }
In the addColumn method, remove the redundant downQuery that sets the column comment to NULL during a rollback, as the column itself is already being dropped.
if (column.comment) {
upQueries.push(
new Query(
`COMMENT ON COLUMN ${this.escapePath(table)}."${column.name}"
IS ${this.escapeComment(column.comment)}`,
),
)
- downQueries.push(- new Query(- `COMMENT ON COLUMN ${this.escapePath(table)}."${column.name}"- IS NULL`,- ),- )
}
Suggestion importance[1-10]: 5
__
Why: The suggestion correctly identifies that the downQuery to nullify the column comment is redundant, as the main downQuery for addColumn already drops the entire column, making this a good logic simplification.
✅ Remove redundant column comment cleanupSuggestion Impact:The suggestion was implemented. The commit removed the redundant if (column.comment) block that was setting column comments to NULL in downQueries within the addColumn method (lines 198-211). This matches the suggestion's intent to eliminate redundant cleanup code since the column is already being dropped during rollback.
code diff:
- if (column.comment) {- upQueries.push(- new Query(- `COMMENT ON COLUMN ${this.escapePath(table)}."${column.name}"- IS ${this.escapeComment(column.comment)}`,- ),- )- downQueries.push(- new Query(- `COMMENT ON COLUMN ${this.escapePath(table)}."${column.name}"- IS NULL`,- ),- )- }
In SapQueryRunner.ts, remove the redundant downQuery that sets a column's comment to NULL within the addColumn method, as the column is already being dropped on rollback.
-if (column.comment) {- upQueries.push(- new Query(- `COMMENT ON COLUMN ${this.escapePath(table)}."${column.name}"- IS ${this.escapeComment(column.comment)}`,- ),- )- downQueries.push(- new Query(- `COMMENT ON COLUMN ${this.escapePath(table)}."${column.name}"- IS NULL`,- ),- )-}+// Remove this block - column comments are cleaned up when the column is dropped
Suggestion importance[1-10]: 5
__
Why: The suggestion correctly identifies that setting a column's comment to NULL in a downQuery is redundant if the column itself is already being dropped in another downQuery for the same operation. However, it incorrectly suggests removing the entire if (column.comment) block, which would also remove the necessary upQuery for adding the comment.
✅ Fix SQL injection and incorrect logicSuggestion Impact:The commit implemented the core suggestion by replacing string interpolation with parameterized queries across all three database types (SAP HANA, PostgreSQL, MySQL/MariaDB). The commit also removed the toUpperCase() call as suggested. Additionally, the commit added extra improvements not in the suggestion: added schema filtering for SAP HANA, and added null-safety checks for all database types to handle empty result sets.
code diff:
const res = await dataSource.query(
- `SELECT "COMMENTS" FROM "SYS"."TABLES" WHERE "TABLE_NAME" = '${tableName.toUpperCase()}'`,+ `SELECT "COMMENTS" FROM "SYS"."TABLES" WHERE "TABLE_NAME" = ? AND "SCHEMA_NAME" = 'SYSTEM'`,+ [tableName],
)
- return res[0]["COMMENTS"]+ return res.length > 0 ? res[0]["COMMENTS"] : undefined
} else if (dbType === "postgres") {
const res = await dataSource.query(
- `SELECT obj_description('${tableName}'::regclass, 'pg_class') AS "comment"`,+ `SELECT obj_description($1::regclass, 'pg_class') AS "comment"`,+ [tableName],
)
- return res[0]["comment"]+ return res.length > 0 ? res[0]["comment"] : undefined
} else if (dbType === "mysql" || dbType === "mariadb") {
const res = await dataSource.query(
- `SELECT \`TABLE_COMMENT\` FROM \`INFORMATION_SCHEMA\`.\`TABLES\` WHERE TABLE_NAME = "${tableName}"`,+ `SELECT \`TABLE_COMMENT\` FROM \`INFORMATION_SCHEMA\`.\`TABLES\` WHERE TABLE_NAME = ?`,+ [tableName],
)
- return res[0]["TABLE_COMMENT"]+ return res.length > 0 ? res[0]["TABLE_COMMENT"] : undefined
Refactor the loadCommentFromDB test helper to use parameterized queries instead of string interpolation to prevent SQL injection, and remove the incorrect toUpperCase() call for SAP HANA table names.
async function loadCommentFromDB(
dataSource: DataSource,
tableName: string,
) {
const dbType = dataSource.driver.options.type
if (dbType === "sap") {
const res = await dataSource.query(
- `SELECT "COMMENTS" FROM "SYS"."TABLES" WHERE "TABLE_NAME" = '${tableName.toUpperCase()}'`,+ `SELECT "COMMENTS" FROM "SYS"."TABLES" WHERE "TABLE_NAME" = ?`,+ [tableName],
)
return res[0]["COMMENTS"]
} else if (dbType === "postgres") {
const res = await dataSource.query(
- `SELECT obj_description('${tableName}'::regclass, 'pg_class') AS "comment"`,+ `SELECT obj_description($1::regclass, 'pg_class') AS "comment"`,+ [tableName],
)
return res[0]["comment"]
} else if (dbType === "mysql" || dbType === "mariadb") {
const res = await dataSource.query(
- `SELECT \`TABLE_COMMENT\` FROM \`INFORMATION_SCHEMA\`.\`TABLES\` WHERE TABLE_NAME = "${tableName}"`,+ `SELECT \`TABLE_COMMENT\` FROM \`INFORMATION_SCHEMA\`.\`TABLES\` WHERE TABLE_NAME = ?`,+ [tableName],
)
return res[0]["TABLE_COMMENT"]
}
return undefined
}
[Suggestion processed]
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies a potential SQL injection vulnerability and a logic bug (toUpperCase()) in the test helper function, improving test robustness and security best practices.
Medium
Possible issue
✅ Handle empty string comments correctlySuggestion Impact:The suggestion was directly implemented in the commit. The escapeComment function was modified to check for empty strings (comment.length === 0) in addition to the existing falsy check, exactly as suggested.
code diff:
- if (!comment) {+ if (!comment || comment.length === 0) {
Update the escapeComment function for the SAP driver to handle empty strings by returning NULL, ensuring consistent behavior for both undefined and empty string comments.
Why: The suggestion correctly identifies that an empty string comment for SAP HANA should be treated as NULL, and proposes a fix to escapeComment that makes the behavior consistent and correct.
Medium
General
Correct assertion for removed table comments
Correct the test assertion for a removed table comment to expect null instead of oneOf([null, ""]), as all relevant drivers should return null.
Why: The suggestion correctly points out that after removing a comment, the expected result should be null across all tested drivers, making the test assertion more precise and accurate.
1. SQL Injection in MySQL createTableSql 🐞 Bug⛨ Security
Description
• The MySQL driver's createTableSql method directly concatenates table.comment into SQL without
proper escaping, creating a SQL injection vulnerability • This is a pre-existing issue not
introduced by this PR, but it's inconsistent with the improved comment handling added in this PR •
Comments containing quotes, backslashes, or null bytes could break the SQL syntax or enable SQL
injection attacks • The escapeComment method exists and is used correctly in changeTableComment
(line 765-779 in the PR), but not in createTableSql (line 3120)
The PR improves comment handling in changeTableComment by using escapeComment, but the pre-existing
createTableSql method at line 3120 still uses unescaped table.comment. This creates an inconsistency
where ALTER TABLE operations are safe but CREATE TABLE operations are vulnerable. The escapeComment
method (line 3294-3305) properly handles backslashes, quotes, and null bytes, but it's not used in
createTableSql.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
# Issue Description
The MySQL driver's createTableSql method has a SQL injection vulnerability where table.comment is directly concatenated into the SQL string without proper escaping. This creates a security risk when creating tables with comments containing special characters.
# Issue Context
The PR improves comment handling in the changeTableComment method by using escapeComment, but the pre-existing createTableSql method still uses unescaped table.comment. The escapeComment method exists and properly handles backslashes, quotes, and null bytes, but it's not used in createTableSql.
The SAP driver's createTableSql (line 3188-3190) correctly uses escapeComment for table comments:
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
✅ 2. SAP Driver Missing Table Comment Creation🐞 Bug✓ Correctness
Description
• The SAP HANA driver does not create table comments during initial table creation via createTable
method • Table comments are only applied during schema synchronization, not when tables are first
created • This creates inconsistency with PostgreSQL and MySQL drivers which both add comments
during table creation • SAP HANA supports COMMENT ON TABLE syntax (proven by the implemented
changeTableComment method), but this capability is not utilized in createTable
The SAP driver's createTable method lacks the table comment creation logic that exists in PostgreSQL
driver. The changeTableComment implementation proves SAP HANA supports the COMMENT ON TABLE syntax,
but this is not used during table creation.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The SAP HANA driver's createTable method does not create table comments during initial table creation. While the changeTableComment method correctly implements COMMENT ON TABLE syntax for SAP HANA, this capability is not utilized when tables are first created.
## Issue Context
- SAP HANA supports COMMENT ON TABLE syntax (proven by changeTableComment implementation at lines 3554-3556)
- PostgreSQL driver correctly adds table comments during createTable (lines 628-640)
- MySQL driver adds comments inline in CREATE TABLE statement (line 3120)
- SAP driver only applies comments during schema synchronization, not initial creation
## Fix Focus Areas
- src/driver/sap/SapQueryRunner.ts[611-649] - Add table comment creation logic after indices handling, before executeQueries call
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
✅ 3. Documentation incomplete for table comments📘 Rule violation✓ Correctness
Description
• The PR adds support for table comments in SAP HANA, which is a user-facing feature. • The
documentation was updated only for column comments (line 147 in decorator-reference.md) but not for
the @Entity decorator's comment option. • The PR checklist explicitly shows documentation was
NOT completed (unchecked box).
+- `comment: string` - Database's column comment. Not supported by all database types. Supported databases: MySQL, MariaDB, PostgreSQL, SAP HANA.
Evidence
The compliance rule requires documentation updates for user-facing changes. The PR adds table
comment support (a user-facing feature) but only documents column comments. The @Entity decorator
reference (lines 19-24) does not list the comment option, and the PR description shows
documentation is incomplete (unchecked box in checklist).
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The PR adds support for table comments via the `@Entity({ comment: "..." })` option, but this option is not documented in the @Entity decorator reference section.
## Issue Context
The feature is user-facing and allows developers to add comments to database tables. The test file shows usage: `@Entity({ comment: "This is a company entity" })`. The decorator reference currently lists options like `name`, `database`, `schema`, `engine`, `synchronize`, and `orderBy` but omits `comment`.
## Fix Focus Areas
- docs/docs/help/3-decorator-reference.md[19-24]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
• The PR introduces a new user-facing feature (table comments support for SAP HANA) but does not
update the documentation. • The @Entity decorator now supports a comment option, but this is not
documented in the decorator reference (docs/docs/help/3-decorator-reference.md). • Users will not be
able to discover or use this feature without proper documentation.
The PR introduces table comment support as a user-facing feature (adding comment option to @Entity
decorator), but the documentation has not been updated. The PR description explicitly shows
documentation was NOT checked off in the pull-request checklist. The decorator reference
documentation at docs/docs/help/3-decorator-reference.md lists @Entity options but does not include
the comment option, and the SAP driver documentation does not mention table comment support.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The PR introduces support for table comments in SAP HANA (and fixes for Postgres/MySQL), but the documentation has not been updated to reflect this new user-facing feature.
## Issue Context
The `@Entity` decorator now accepts a `comment` option that allows users to add comments to database tables. This feature is now supported in SAP HANA, PostgreSQL, MySQL, and MariaDB drivers. Users need to know about this option to use it.
## Fix Focus Areas
- docs/docs/help/3-decorator-reference.md[18-24] - Add `comment` to the list of @Entity options
- docs/docs/drivers/sap.md[1-76] - Optionally add a section about table comment support
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
5. Test hardcodes SAP HANA schema as 'SYSTEM' 🐞 Bug⛯ Reliability⭐ New
Description
The loadCommentFromDB test helper hardcodes SCHEMA_NAME = 'SYSTEM' in its SAP HANA query. If
tests run against a SAP HANA instance where the test user has a different default schema, the query
returns no rows and comment assertions will fail with undefined.
+ if (dbType === "sap") {+ const res = await dataSource.query(+ `SELECT "COMMENTS" FROM "SYS"."TABLES" WHERE "TABLE_NAME" = ? AND "SCHEMA_NAME" = 'SYSTEM'`,+ [tableName],+ )+ return res.length > 0 ? res[0]["COMMENTS"] : undefined
Evidence
The production SapQueryRunner.loadTables resolves the schema dynamically via getCurrentSchema(),
but the test helper bypasses this and hardcodes 'SYSTEM'. This makes the test fragile for any
non-default SAP HANA configuration.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The `loadCommentFromDB` helper in the SAP HANA test branch hardcodes `SCHEMA_NAME = 'SYSTEM'`. This will silently return `undefined` when tests run against a SAP HANA instance where the test user has a different default schema, causing assertion failures.
## Issue Context
- The production code in `SapQueryRunner.loadTables` correctly resolves the schema dynamically via `getCurrentSchema()`.
- SAP HANA exposes the current schema via `SELECT CURRENT_SCHEMA FROM DUMMY`.
## Fix Focus Areas
- Replace the hardcoded schema filter with a dynamic schema lookup in the test helper:
- test/functional/query-runner/create-comment.test.ts[31-36]
Example fix:
```typescript
if (dbType === "sap") {
const schemaRes = await dataSource.query(`SELECT CURRENT_SCHEMA FROM DUMMY`)
const schema = schemaRes[0]["CURRENT_SCHEMA"]
const res = await dataSource.query(
`SELECT "COMMENTS" FROM "SYS"."TABLES" WHERE "TABLE_NAME" = ? AND "SCHEMA_NAME" = ?`,
[tableName, schema],
)
return res.length > 0 ? res[0]["COMMENTS"] : undefined
}
```
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
• The PR adds numerous @param JSDoc tags to existing methods in SapQueryRunner.ts that previously
had only description comments without parameter documentation. • This pattern is inconsistent with
the existing codebase style where most methods have only description comments without @param tags
(e.g., lines 411-412, 443-444, 454-455, 478-479). • The added @param tags appear to be AI-generated
noise as they don't add meaningful documentation value and deviate from the established file
conventions.
+ * @param isolationLevel
*/
async startTransaction(isolationLevel?: IsolationLevel): Promise<void> {
if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()
Evidence
The compliance rule 'Remove AI-generated noise' requires that changes should not introduce AI-like
comments or style inconsistent with the file. The SapQueryRunner.ts file shows a clear pattern where
most methods have only description comments without @param tags (lines 411-412, 443-444, 454-455,
478-479 show methods with descriptions only). The PR adds @param tags to dozens of methods (lines
106, 173-174, 193-195, 336-339, 423, 435, 470, 490, 507-508, etc.), which is inconsistent with the
existing style. Similar query runner files like MysqlQueryRunner.ts and PostgresQueryRunner.ts also
follow the pattern of having description-only comments for most methods.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The PR adds numerous @param JSDoc tags to existing methods in SapQueryRunner.ts, which is inconsistent with the established documentation style in the file. Most methods in this file and similar query runner files have only description comments without @param tags.
## Issue Context
The file follows a pattern where methods have concise description-only JSDoc comments. Adding @param tags to dozens of methods creates inconsistency and appears to be AI-generated noise that doesn&#x27;t add meaningful documentation value.
## Fix Focus Areas
- src/driver/sap/SapQueryRunner.ts[106-106]
- src/driver/sap/SapQueryRunner.ts[173-174]
- src/driver/sap/SapQueryRunner.ts[193-195]
- src/driver/sap/SapQueryRunner.ts[336-339]
- src/driver/sap/SapQueryRunner.ts[423-423]
- src/driver/sap/SapQueryRunner.ts[435-435]
- src/driver/sap/SapQueryRunner.ts[470-470]
- src/driver/sap/SapQueryRunner.ts[490-490]
- src/driver/sap/SapQueryRunner.ts[507-508]
- src/driver/sap/SapQueryRunner.ts[528-529]
- src/driver/sap/SapQueryRunner.ts[540-541]
- src/driver/sap/SapQueryRunner.ts[549-550]
- src/driver/sap/SapQueryRunner.ts[577-579]
- src/driver/sap/SapQueryRunner.ts[606-609]
- src/driver/sap/SapQueryRunner.ts[653-656]
- src/driver/sap/SapQueryRunner.ts[702-703]
- src/driver/sap/SapQueryRunner.ts[722-722]
- src/driver/sap/SapQueryRunner.ts[739-740]
- src/driver/sap/SapQueryRunner.ts[949-950]
- src/driver/sap/SapQueryRunner.ts[1147-1148]
- src/driver/sap/SapQueryRunner.ts[1161-1163]
- src/driver/sap/SapQueryRunner.ts[1194-1196]
- src/driver/sap/SapQueryRunner.ts[1617-1618]
- src/driver/sap/SapQueryRunner.ts[1631-1632]
- src/driver/sap/SapQueryRunner.ts[1878-1879]
- src/driver/sap/SapQueryRunner.ts[1892-1893]
- src/driver/sap/SapQueryRunner.ts[1919-1920]
- src/driver/sap/SapQueryRunner.ts[2070-2070]
- src/driver/sap/SapQueryRunner.ts[2172-2173]
- src/driver/sap/SapQueryRunner.ts[2186-2187]
- src/driver/sap/SapQueryRunner.ts[2200-2201]
- src/driver/sap/SapQueryRunner.ts[2214-2215]
- src/driver/sap/SapQueryRunner.ts[2228-2229]
- src/driver/sap/SapQueryRunner.ts[2255-2256]
- src/driver/sap/SapQueryRunner.ts[2270-2271]
- src/driver/sap/SapQueryRunner.ts[2296-2297]
- src/driver/sap/SapQueryRunner.ts[2311-2312]
- src/driver/sap/SapQueryRunner.ts[2325-2326]
- src/driver/sap/SapQueryRunner.ts[2339-2340]
- src/driver/sap/SapQueryRunner.ts[2353-2354]
- src/driver/sap/SapQueryRunner.ts[2367-2368]
- src/driver/sap/SapQueryRunner.ts[2395-2396]
- src/driver/sap/SapQueryRunner.ts[2410-2411]
- src/driver/sap/SapQueryRunner.ts[2445-2446]
- src/driver/sap/SapQueryRunner.ts[2460-2461]
- src/driver/sap/SapQueryRunner.ts[2482-2483]
- src/driver/sap/SapQueryRunner.ts[2497-2498]
- src/driver/sap/SapQueryRunner.ts[2526-2527]
- src/driver/sap/SapQueryRunner.ts[2542-2542]
- src/driver/sap/SapQueryRunner.ts[2650-2650]
- src/driver/sap/SapQueryRunner.ts[3049-3050]
- src/driver/sap/SapQueryRunner.ts[3197-3198]
- src/driver/sap/SapQueryRunner.ts[3245-3245]
- src/driver/sap/SapQueryRunner.ts[3253-3253]
- src/driver/sap/SapQueryRunner.ts[3283-3284]
- src/driver/sap/SapQueryRunner.ts[3307-3308]
- src/driver/sap/SapQueryRunner.ts[3330-3331]
- src/driver/sap/SapQueryRunner.ts[3350-3350]
- src/driver/sap/SapQueryRunner.ts[3367-3368]
- src/driver/sap/SapQueryRunner.ts[3383-3384]
- src/driver/sap/SapQueryRunner.ts[3402-3403]
- src/driver/sap/SapQueryRunner.ts[3448-3449]
- src/driver/sap/SapQueryRunner.ts[3469-3469]
- src/driver/sap/SapQueryRunner.ts[3483-3483]
- src/driver/sap/SapQueryRunner.ts[3497-3499]
- src/driver/sap/SapQueryRunner.ts[3533-3534]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
✅ 7. Test missing issue reference comment📘 Rule violation✓ Correctness
Description
• The functional test does not include a reference to issue #10621 in a comment. • Compliance rule 3
requires issue references in test comments when applicable. • While the test is correctly placed in
test/functional, it should include a comment referencing the issue for traceability.
The compliance rule states that issue fixes should add or update tests in test/functional with an
issue reference in the test comment when applicable. The test is correctly placed in
test/functional, but lacks a comment referencing issue #10621. Other functional tests in the
codebase include issue references (e.g., '// GitHub issue #7738', '// Github issue #5321').
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The functional test for table comments should include a reference to the GitHub issue it addresses for better traceability.
## Issue Context
This test was added to fix issue #10621. Following the project&#x27;s pattern of including issue references in test comments, a comment should be added.
## Fix Focus Areas
- test/functional/query-runner/create-comment.test.ts[10-10] - Add comment like &#x27;// GitHub issue #10621&#x27; before the describe block
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
ⓘ The new review experience is currently in Beta. Learn more
1. SQL Injection in MySQL createTableSql 🐞 Bug⛨ Security
Description
• The MySQL driver's createTableSql method directly concatenates table.comment into SQL without
proper escaping, creating a SQL injection vulnerability
• This is a pre-existing issue not introduced by this PR, but it's inconsistent with the improved
comment handling added in this PR
• Comments containing quotes, backslashes, or null bytes could break the SQL syntax or enable SQL
injection attacks
• The escapeComment method exists and is used correctly in changeTableComment (line 765-779 in the
PR), but not in createTableSql (line 3120)
The PR improves comment handling in changeTableComment by using escapeComment, but the pre-existing
createTableSql method at line 3120 still uses unescaped table.comment. This creates an inconsistency
where ALTER TABLE operations are safe but CREATE TABLE operations are vulnerable. The escapeComment
method (line 3294-3305) properly handles backslashes, quotes, and null bytes, but it's not used in
createTableSql.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
# Issue Description
The MySQL driver's createTableSql method has a SQL injection vulnerability where table.comment is directly concatenated into the SQL string without proper escaping. This creates a security risk when creating tables with comments containing special characters.
# Issue Context
The PR improves comment handling in the changeTableComment method by using escapeComment, but the pre-existing createTableSql method still uses unescaped table.comment. The escapeComment method exists and properly handles backslashes, quotes, and null bytes, but it's not used in createTableSql.
The SAP driver's createTableSql (line 3188-3190) correctly uses escapeComment for table comments:
```typescript
if (table.comment) {
sql += ` COMMENT ${this.escapeComment(table.comment)}`
}
```
# Fix Focus Areas
- src/driver/mysql/MysqlQueryRunner.ts[3119-3121]
Change from:
```typescript
if (table.comment) {
sql += ` COMMENT="${table.comment}"`
}
```
To:
```typescript
if (table.comment) {
sql += ` COMMENT=${this.escapeComment(table.comment)}`
}
```
Note: Remove the double quotes around the comment value since escapeComment already adds the necessary quotes.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
• The PR adds numerous @param JSDoc tags to existing methods in SapQueryRunner.ts that previously
had only description comments without parameter documentation.
• This pattern is inconsistent with the existing codebase style where most methods have only
description comments without @param tags (e.g., lines 411-412, 443-444, 454-455, 478-479).
• The added @param tags appear to be AI-generated noise as they don't add meaningful documentation
value and deviate from the established file conventions.
+ * @param isolationLevel
*/
async startTransaction(isolationLevel?: IsolationLevel): Promise<void> {
if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()
Evidence
The compliance rule 'Remove AI-generated noise' requires that changes should not introduce AI-like
comments or style inconsistent with the file. The SapQueryRunner.ts file shows a clear pattern where
most methods have only description comments without @param tags (lines 411-412, 443-444, 454-455,
478-479 show methods with descriptions only). The PR adds @param tags to dozens of methods (lines
106, 173-174, 193-195, 336-339, 423, 435, 470, 490, 507-508, etc.), which is inconsistent with the
existing style. Similar query runner files like MysqlQueryRunner.ts and PostgresQueryRunner.ts also
follow the pattern of having description-only comments for most methods.
✅ 1. SAP Driver Missing Table Comment Creation 🐞 Bug✓ CorrectnessSuggestion Impact:The commit implemented the suggestion by adding table comment support directly in the CREATE TABLE statement (lines 508-510). Instead of using a separate COMMENT ON TABLE query after table creation as suggested, the implementation adds the comment inline using COMMENT syntax within the CREATE TABLE SQL statement, which is a valid and more efficient approach for SAP HANA.
code diff:
@@ -3112,11 +3185,17 @@
sql += `)`
+ if (table.comment) {+ sql += ` COMMENT ${this.escapeComment(table.comment)}`+ }+
return new Query(sql)
Description
• The SAP HANA driver does not create table comments during initial table creation via createTable
method
• Table comments are only applied during schema synchronization, not when tables are first created
• This creates inconsistency with PostgreSQL and MySQL drivers which both add comments during table
creation
• SAP HANA supports COMMENT ON TABLE syntax (proven by the implemented changeTableComment method),
but this capability is not utilized in createTable
The SAP driver's createTable method lacks the table comment creation logic that exists in PostgreSQL
driver. The changeTableComment implementation proves SAP HANA supports the COMMENT ON TABLE syntax,
but this is not used during table creation.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue Description
The SAP HANA driver's createTable method does not create table comments during initial table creation. While the changeTableComment method correctly implements COMMENT ON TABLE syntax for SAP HANA, this capability is not utilized when tables are first created.
## Issue Context
- SAP HANA supports COMMENT ON TABLE syntax (proven by changeTableComment implementation at lines 3554-3556)
- PostgreSQL driver correctly adds table comments during createTable (lines 628-640)
- MySQL driver adds comments inline in CREATE TABLE statement (line 3120)
- SAP driver only applies comments during schema synchronization, not initial creation
## Fix Focus Areas
- src/driver/sap/SapQueryRunner.ts[611-649] - Add table comment creation logic after indices handling, before executeQueries call
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
✅ 1. Documentation incomplete for table comments 📘 Rule violation✓ CorrectnessSuggestion Impact:The commit directly implements the suggestion by adding documentation for the comment option in the @entity decorator reference section (line 6) and including a usage example in the code sample (line 14). This addresses the incomplete documentation issue raised in the suggestion.
code diff:
+- `comment` - Database table comment. Not supported by all database types. Currently supported by MySQL, MariaDB, PostgreSQL, SAP HANA.
- `engine` - database engine to be set during table creation (works only in some databases).
- `synchronize` - entities marked with `false` are skipped from schema updates.
- `orderBy` - specifies default ordering for entities when using `find` operations and `QueryBuilder`.
@@ -31,6 +32,7 @@
engine: "MyISAM",
database: "example_dev",
schema: "schema_with_best_tables",
+ comment: "This is users table",
Description
• The PR adds support for table comments in SAP HANA, which is a user-facing feature.
• The documentation was updated only for column comments (line 147 in decorator-reference.md) but
not for the @Entity decorator's comment option.
• The PR checklist explicitly shows documentation was NOT completed (unchecked box).
+- `comment: string` - Database's column comment. Not supported by all database types. Supported databases: MySQL, MariaDB, PostgreSQL, SAP HANA.
Evidence
The compliance rule requires documentation updates for user-facing changes. The PR adds table
comment support (a user-facing feature) but only documents column comments. The @Entity decorator
reference (lines 19-24) does not list the comment option, and the PR description shows
documentation is incomplete (unchecked box in checklist).
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The PR adds support for table comments via the `@Entity({ comment: "..." })` option, but this option is not documented in the @Entity decorator reference section.
## Issue Context
The feature is user-facing and allows developers to add comments to database tables. The test file shows usage: `@Entity({ comment: "This is a company entity" })`. The decorator reference currently lists options like `name`, `database`, `schema`, `engine`, `synchronize`, and `orderBy` but omits `comment`.
## Fix Focus Areas
- docs/docs/help/3-decorator-reference.md[19-24]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
✅ 1. Table comment feature lacks documentation 📘 Rule violation✓ CorrectnessSuggestion Impact:The commit directly implements the suggestion by adding documentation for the 'comment' option in the @entity decorator reference. It adds the option to the list with a description of supported databases (MySQL, MariaDB, PostgreSQL, SAP HANA) and includes an example usage in the code sample.
code diff:
@@ -19,6 +19,7 @@
- `name` - table name. If not specified, then table name is generated from entity class name.
- `database` - database name in selected DB server.
- `schema` - schema name.
+- `comment` - Database table comment. Not supported by all database types. Currently supported by MySQL, MariaDB, PostgreSQL, SAP HANA.
- `engine` - database engine to be set during table creation (works only in some databases).
- `synchronize` - entities marked with `false` are skipped from schema updates.
- `orderBy` - specifies default ordering for entities when using `find` operations and `QueryBuilder`.
@@ -31,6 +32,7 @@
engine: "MyISAM",
database: "example_dev",
schema: "schema_with_best_tables",
+ comment: "This is users table",
synchronize: false,
orderBy: {
name: "ASC",
Description
• The PR introduces a new user-facing feature (table comments support for SAP HANA) but does not
update the documentation.
• The @Entity decorator now supports a comment option, but this is not documented in the
decorator reference (docs/docs/help/3-decorator-reference.md).
• Users will not be able to discover or use this feature without proper documentation.
The PR introduces table comment support as a user-facing feature (adding comment option to @Entity
decorator), but the documentation has not been updated. The PR description explicitly shows
documentation was NOT checked off in the pull-request checklist. The decorator reference
documentation at docs/docs/help/3-decorator-reference.md lists @Entity options but does not include
the comment option, and the SAP driver documentation does not mention table comment support.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The PR introduces support for table comments in SAP HANA (and fixes for Postgres/MySQL), but the documentation has not been updated to reflect this new user-facing feature.
## Issue Context
The `@Entity` decorator now accepts a `comment` option that allows users to add comments to database tables. This feature is now supported in SAP HANA, PostgreSQL, MySQL, and MariaDB drivers. Users need to know about this option to use it.
## Fix Focus Areas
- docs/docs/help/3-decorator-reference.md[18-24] - Add `comment` to the list of @Entity options
- docs/docs/drivers/sap.md[1-76] - Optionally add a section about table comment support
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
✅ 2. Test missing issue reference comment 📘 Rule violation✧ QualitySuggestion Impact:The commit added the exact comment suggested: "// GitHub issue #10621 - Table comments not supported by typeorm for SAP HANA" at line 6, right before the "table comment" describe block.
code diff:
+ // GitHub issue #10621 - Table comments not supported by typeorm for SAP HANA
Description
• The functional test does not include a reference to issue #10621 in a comment.
• Compliance rule 3 requires issue references in test comments when applicable.
• While the test is correctly placed in test/functional, it should include a comment referencing the
issue for traceability.
The compliance rule states that issue fixes should add or update tests in test/functional with an
issue reference in the test comment when applicable. The test is correctly placed in
test/functional, but lacks a comment referencing issue #10621. Other functional tests in the
codebase include issue references (e.g., '// GitHub issue #7738', '// Github issue #5321').
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The functional test for table comments should include a reference to the GitHub issue it addresses for better traceability.
## Issue Context
This test was added to fix issue #10621. Following the project's pattern of including issue references in test comments, a comment should be added.
## Fix Focus Areas
- test/functional/query-runner/create-comment.test.ts[10-10] - Add comment like '// GitHub issue #10621' before the describe block
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close #10621
Summary
This PR introduces support for table comments in SAP HANA.
Changes
changeTableCommentmethod in theSapQueryRunner.changeTableCommentmethods in thePostgresQueryRunnerandMysqlQueryRunner.Closes #10621
Pull-Request Checklist
masterbranchFixes #10621tests/**.test.ts)docs/docs/**.md)