Repository navigation
feat(oracle): add oracle support - #18050
Conversation
…d showConstraints and test cases related to that
…createTableQuery() and data-type tests
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (10)
packages/core/test/unit/query-generator/create-schema-query.test.ts (2)
16-16: Role quoting and idempotency issues remain in Oracle CREATE SCHEMA expectation.The password security concern from the previous review has been resolved (now using
IDENTIFIED EXTERNALLY). However, two issues remain:
Incorrect role quoting: Oracle predefined role names like
CONNECTshould be granted without quotes. The expectation should useGRANT CONNECT TO "mySchema"instead ofGRANT "CONNECT" TO "mySchema"(and similarly for other system privileges).Partial idempotency: The grants only execute when
NOT USER_FOUND(i.e., user newly created). If the user already exists but lacks required permissions, no grants are re-applied, potentially leaving the user in an incomplete state.These issues should be addressed in the implementation (
packages/oracle/src/query-generator-typescript.internal.ts) and the test expectation updated accordingly.
128-132: Incomplete list of invalid options for Oracle in combined options test.The Oracle expectation only lists 3 invalid options but should list 6. Based on the individual option tests:
- Line 65:
commentis only supported by Snowflake, so Oracle should reject it- Line 74:
ifNotExistsis explicitly rejected by Oracle- Line 84:
replaceis only supported by MariaDB and Snowflake, so Oracle should reject it🔎 Apply this diff to add the missing invalid options:
oracle: buildInvalidOptionReceivedError('createSchemaQuery', dialectName, [ 'authorization', 'charset', 'collate', + 'comment', + 'ifNotExists', + 'replace', ]),packages/oracle/src/query-generator-typescript.internal.ts (2)
396-408: Fix transaction SQL to use Oracle syntax.Lines 397 and 407 return T-SQL syntax (
COMMIT TRANSACTION/ROLLBACK TRANSACTION), which Oracle does not support. Oracle requiresCOMMITandROLLBACKwithout theTRANSACTIONkeyword. Since the Oracle dialect does not setconnectionTransactionMethods: true, these methods will be invoked and produce runtime SQL errors.🔎 Apply this diff to fix the SQL syntax:
commitTransactionQuery() { - return 'COMMIT TRANSACTION'; + return 'COMMIT'; } rollbackTransactionQuery(): string { if (this.dialect.supports.connectionTransactionMethods) { throw new Error( `rollbackTransactionQuery is not supported by the ${this.dialect.name} dialect.`, ); } - return 'ROLLBACK TRANSACTION'; + return 'ROLLBACK'; }
140-157:IF EXISTSinremoveConstraintQueryis still present despite being marked resolved.The past review comment flagged that Oracle does not support
IF EXISTSinDROP CONSTRAINTclauses (line 150), marked as "✅ Addressed in commit 8454ae2." However, the code still emitsIF EXISTSwhenoptions?.ifExistsis true for sys-prefixed constraints, which will cause ORA-11557 runtime errors.Either validate and reject the
ifExistsoption before building SQL, or implement PL/SQL conditional logic querying the data dictionary to check constraint existence.packages/oracle/src/query-generator.js (3)
320-322: Fix index shifting bug when splicingoptions.indexes.Splicing array elements while iterating
idxToDeletein forward order causes index misalignment. After the firstsplice, remaining indices point to wrong elements. This results in incorrect indexes being removed.🔎 Apply this diff to fix (reverse iteration):
- idxToDelete.forEach(idx => { - options.indexes.splice(idx, 1); - }); + // Splice in reverse order to avoid index shifting + for (let i = idxToDelete.length - 1; i >= 0; i--) { + options.indexes.splice(idxToDelete[i], 1); + }Or use
filterto rebuild the array:- idxToDelete.forEach(idx => { - options.indexes.splice(idx, 1); - }); + const idxSet = new Set(idxToDelete); + options.indexes = options.indexes.filter((_, idx) => !idxSet.has(idx));
898-899: Fix unreachable DOUBLE condition inattributeToSQL.Line 898 compares
attribute.type === 'DOUBLE'(strict equality with a string), butattribute.typeis a DataType class instance. This condition is unreachable dead code and inconsistent with other branches that useinstanceof(lines 870, 882, 889).🔎 Apply this diff to fix:
- } else if (attribute.type && attribute.type === 'DOUBLE') { - template = attribute.type.toSql(); + } else if (attribute.type instanceof DataTypes.DOUBLE) { + template = attribute.type.toSql();
690-696: Fix auto-increment detection to check all rows, not just the last one.The loop overwrites
allColumns[key]for each row (lines 692-695), so only the last row's value determines the final state. A mix ofnulland non-nullvalues for an auto-increment column is only detected when the last row isnull. If the last row is non-null, the mix passes silently.🔎 Apply this diff to enforce the invariant across all rows:
+ const sawNull = {}; + const sawNonNull = {}; + for (const fieldValueHash of fieldValueHashes) { forOwn(fieldValueHash, (value, key) => { - allColumns[key] = - fieldMappedAttributes[key] && - fieldMappedAttributes[key].autoIncrement === true && - value === null; + if (!fieldMappedAttributes[key]?.autoIncrement) { + allColumns[key] = false; + return; + } + + const isNull = value === null; + sawNull[key] ||= isNull; + sawNonNull[key] ||= !isNull; + + if (sawNull[key] && sawNonNull[key]) { + throw new Error( + 'For an auto-increment column either all rows must be null or non-null; a mix is not allowed.', + ); + } + + allColumns[key] = sawNull[key]; }); }packages/oracle/src/dialect.ts (3)
109-111:getDefaultSchemawill throw in non-replication setups.Line 110 accesses
this.sequelize.options.replication.write.usernamewithout safe optional chaining onreplicationorwrite. In default (non-replication) configurations,replicationorwritewill be undefined, causing a runtime error before the optional chaining onusernameis evaluated.🔎 Apply this diff to fix:
getDefaultSchema(): string { - return this.sequelize.options.replication.write.username?.toUpperCase() ?? ''; + const replicationUser = this.sequelize.options.replication?.write?.username; + const directUser = this.sequelize.options.username; + const username = replicationUser ?? directUser; + return username?.toUpperCase() ?? ''; }
88-90: Update documentation URL to match minimum database version.Line 88 links to Oracle Database 23 documentation, but line 89 declares
minimumDatabaseVersion: '18.0.0'. Oracle 23 introduced features unavailable in 18 (native JSON SQL type, SQL Domains, spatial enhancements). The documentation should align with the declared minimum version.🔎 Apply this diff:
- dataTypesDocumentationUrl: - 'https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/Data-Types.html', + dataTypesDocumentationUrl: + 'https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/Data-Types.html',
141-146: Fix typos in comments.Line 141: "indicated y the last empty string" should be "indicated by the last empty string"
Line 146: Comment mentions "TIMESTAM_TZ" but should be "TIMESTAMP_TZ"
🔎 Apply this diff:
// Validate that the split result has exactly three parts (function name, parameters, and an empty string) - // and that there are no additional SQL commands after the function call (indicated y the last empty string). + // and that there are no additional SQL commands after the function call (indicated by the last empty string). if (splitVal.length !== 3 || splitVal[2] !== '') { throw new Error('Invalid SQL function call.'); // Error if function call has unexpected format } - // Extract the function name (either 'TO_TIMESTAM_TZ' or 'TO_DATE') and the contents inside the parentheses + // Extract the function name (either 'TO_TIMESTAMP_TZ' or 'TO_DATE') and the contents inside the parentheses
🧹 Nitpick comments (2)
packages/core/src/abstract-dialect/dialect.ts (1)
244-247: Consider using consistent comment style.The comment uses
//inline style, while other properties inDialectSupportsuse/* */block comment style. This is a minor consistency nit.🔎 Apply this diff for consistent comment style:
dropTable: { cascade: boolean; - concurrentDropConstraints: boolean; // If Constraints on same table can be dropped concurrently. + /** Whether constraints on the same table can be dropped concurrently */ + concurrentDropConstraints: boolean; };packages/oracle/src/dialect.ts (1)
16-16: Consider using a type alias for the empty OracleDialectOptions.The empty
OracleDialectOptionsinterface is functionally equivalent to{}. While valid as a placeholder for future options, a type alias is slightly cleaner for empty definitions.🔎 Apply this diff if preferred:
-export interface OracleDialectOptions {} +export type OracleDialectOptions = Record<string, never>;Or simply:
-export interface OracleDialectOptions {} +// eslint-disable-next-line @typescript-eslint/no-empty-object-type +export interface OracleDialectOptions {}Based on static analysis hint from Biome.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
packages/core/src/abstract-dialect/dialect.ts(5 hunks)packages/core/test/unit/query-generator/create-schema-query.test.ts(4 hunks)packages/oracle/src/dialect.ts(1 hunks)packages/oracle/src/query-generator-typescript.internal.ts(1 hunks)packages/oracle/src/query-generator.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
packages/**/test/**/*.test.ts
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Name unit tests with the .test.ts suffix
Files:
packages/core/test/unit/query-generator/create-schema-query.test.ts
packages/**/test/**/*.test.{js,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
packages/**/test/**/*.test.{js,ts}: Use Support.getTestDialectTeaser() for dialect-specific test descriptions
Use beforeEach/afterEach to sync with { force: true } and close Sequelize instances in tests
In tests, skip unsupported behavior with dialect.supports.featureName checks
Files:
packages/core/test/unit/query-generator/create-schema-query.test.ts
packages/*/src/query-generator.{js,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Implement dialect feature SQL in query-generator.ts (preferred) or legacy query-generator.js
Files:
packages/oracle/src/query-generator.js
packages/**/src/**/*.js
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Write all new implementations in TypeScript; avoid creating new .js files in src
Files:
packages/oracle/src/query-generator.js
packages/**/src/**/query-generator.{js,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
When modifying query generation, update both the base query generator and all dialect-specific implementations
Files:
packages/oracle/src/query-generator.js
packages/*/src/dialect.ts
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
When adding a dialect feature, update packages/{dialect}/src/dialect.ts to declare feature support flags
Files:
packages/oracle/src/dialect.ts
🧠 Learnings (11)
📓 Common learnings
Learnt from: CR
Repo: sequelize/sequelize PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-29T19:49:24.715Z
Learning: Applies to packages/*/src/query-generator.{js,ts} : Implement dialect feature SQL in query-generator.ts (preferred) or legacy query-generator.js
📚 Learning: 2025-09-29T19:49:24.715Z
Learnt from: CR
Repo: sequelize/sequelize PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-29T19:49:24.715Z
Learning: Applies to packages/*/src/query-interface.{js,ts} : Add schema operations for new features in query-interface.ts (preferred) or legacy query-interface.js
Applied to files:
packages/core/test/unit/query-generator/create-schema-query.test.tspackages/oracle/src/query-generator-typescript.internal.tspackages/oracle/src/query-generator.jspackages/core/src/abstract-dialect/dialect.tspackages/oracle/src/dialect.ts
📚 Learning: 2025-09-29T19:49:24.715Z
Learnt from: CR
Repo: sequelize/sequelize PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-29T19:49:24.715Z
Learning: Applies to packages/**/src/**/query-generator.{js,ts} : When modifying query generation, update both the base query generator and all dialect-specific implementations
Applied to files:
packages/core/test/unit/query-generator/create-schema-query.test.tspackages/oracle/src/query-generator-typescript.internal.tspackages/oracle/src/query-generator.jspackages/core/src/abstract-dialect/dialect.tspackages/oracle/src/dialect.ts
📚 Learning: 2025-09-29T19:49:24.715Z
Learnt from: CR
Repo: sequelize/sequelize PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-29T19:49:24.715Z
Learning: Applies to packages/*/src/query-generator.{js,ts} : Implement dialect feature SQL in query-generator.ts (preferred) or legacy query-generator.js
Applied to files:
packages/core/test/unit/query-generator/create-schema-query.test.tspackages/oracle/src/query-generator-typescript.internal.tspackages/oracle/src/query-generator.jspackages/core/src/abstract-dialect/dialect.tspackages/oracle/src/dialect.ts
📚 Learning: 2025-09-29T19:49:24.715Z
Learnt from: CR
Repo: sequelize/sequelize PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-29T19:49:24.715Z
Learning: Applies to packages/**/test/**/*.test.{js,ts} : In tests, skip unsupported behavior with dialect.supports.featureName checks
Applied to files:
packages/core/test/unit/query-generator/create-schema-query.test.tspackages/core/src/abstract-dialect/dialect.ts
📚 Learning: 2025-09-29T19:49:24.715Z
Learnt from: CR
Repo: sequelize/sequelize PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-29T19:49:24.715Z
Learning: Applies to packages/*/src/dialect.ts : When adding a dialect feature, update packages/{dialect}/src/dialect.ts to declare feature support flags
Applied to files:
packages/oracle/src/query-generator.jspackages/core/src/abstract-dialect/dialect.tspackages/oracle/src/dialect.ts
📚 Learning: 2025-09-29T19:49:24.715Z
Learnt from: CR
Repo: sequelize/sequelize PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-29T19:49:24.715Z
Learning: Co-locate TypeScript type definitions with their implementation files
Applied to files:
packages/oracle/src/query-generator.js
📚 Learning: 2025-09-29T19:49:24.715Z
Learnt from: CR
Repo: sequelize/sequelize PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-29T19:49:24.715Z
Learning: Applies to packages/**/src/**/*.js : Write all new implementations in TypeScript; avoid creating new .js files in src
Applied to files:
packages/oracle/src/query-generator.js
📚 Learning: 2025-11-08T03:05:56.951Z
Learnt from: SippieCup
Repo: sequelize/sequelize PR: 18051
File: packages/core/src/utils/undot.ts:177-177
Timestamp: 2025-11-08T03:05:56.951Z
Learning: In packages/core/src/utils/undot.ts, the defensive check "if (!Array.isArray(obj))" before numeric leaf assignment in setByPathArray is intentional to handle edge cases where table aliases or oddly-named columns produce single-segment numeric keys (e.g., "0").
Applied to files:
packages/oracle/src/query-generator.js
📚 Learning: 2025-09-29T19:49:24.715Z
Learnt from: CR
Repo: sequelize/sequelize PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-29T19:49:24.715Z
Learning: Prefer TypeScript for all new code; only modify existing .js files when necessary
Applied to files:
packages/oracle/src/query-generator.js
📚 Learning: 2025-09-29T19:49:24.715Z
Learnt from: CR
Repo: sequelize/sequelize PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-29T19:49:24.715Z
Learning: Applies to packages/**/test/**/*.test.{js,ts} : Use Support.getTestDialectTeaser() for dialect-specific test descriptions
Applied to files:
packages/core/src/abstract-dialect/dialect.tspackages/oracle/src/dialect.ts
🧬 Code graph analysis (2)
packages/core/test/unit/query-generator/create-schema-query.test.ts (1)
packages/core/src/utils/check.ts (1)
buildInvalidOptionReceivedError(88-96)
packages/oracle/src/query-generator.js (3)
packages/oracle/src/query-generator-typescript.internal.ts (1)
OracleQueryGeneratorTypeScript(34-409)packages/core/src/utils/check.ts (1)
rejectInvalidOptions(33-54)packages/core/src/abstract-dialect/query-generator.js (4)
CREATE_TABLE_QUERY_SUPPORTABLE_OPTIONS(43-51)CREATE_TABLE_QUERY_SUPPORTABLE_OPTIONS(43-51)ADD_COLUMN_QUERY_SUPPORTABLE_OPTIONS(52-52)ADD_COLUMN_QUERY_SUPPORTABLE_OPTIONS(52-52)
🪛 Biome (2.1.2)
packages/oracle/src/query-generator.js
[error] 4-5: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 5-6: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 6-7: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 7-8: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 8-9: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 9-10: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 11-12: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 12-13: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 13-17: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 17-18: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 18-19: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 19-20: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 20-25: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 25-26: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 26-27: Illegal use of an import declaration outside of a module
not allowed inside scripts
(parse)
[error] 154-1165: Illegal use of an export declaration outside of a module
not allowed inside scripts
(parse)
packages/oracle/src/dialect.ts
[error] 16-16: An empty interface is equivalent to {}.
Safe fix: Use a type alias instead.
(lint/suspicious/noEmptyInterface)
⏰ 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). (2)
- GitHub Check: Upload install and build artifact (Node 18)
- GitHub Check: Upload install and build artifact (Node 20)
🔇 Additional comments (4)
packages/core/src/abstract-dialect/dialect.ts (4)
71-75: LGTM!The new
returnIntoValuesandtopLevelOrderByRequiredcapability flags are well-documented and properly typed. These additions support Oracle-specific behaviors for RETURNING INTO binds and ORDER BY requirements.
116-118: LGTM!The type expansion to
false | stringproperly models dialects that don't support ignore-duplicates semantics (Oracle, DB2, IBMi) versus those that use dialect-specific keywords.
336-337: LGTM!Default values of
falsefor both properties are appropriate, requiring Oracle (and any other dialect needing these features) to explicitly opt-in.
471-474: LGTM!Defaulting
concurrentDropConstraints: truemaintains backward compatibility for existing dialects while allowing Oracle to override this tofalsein its dialect implementation.
Thanks. I have addressed all the comments. |
|
@WikiRik Wish you a very Happy New Year! |
|
Thanks for the reminder. I finally finished the review. This looks good enough to release in the alpha. Sorry for the wait and thanks for all the hard work! |
Pull Request Checklist
Description of Changes
This change fixes CI issues on top of PR #17403.
Major updates:
Oracle upsert:
The Oracle dialect generates both
updateQueryandinsertQuery, combining them into a single PL/SQL block with binds.To ensure bind numbering continues correctly between the two queries,
createBindParamGeneratorwas updated to accept the dialect parameter and continue numbering based onObject.keys(bind).length.Oracle bulkInsert:
Skips mapBindParameters and bind generation since Oracle uses an array of arrays for multi-row bind batches.
ignoreDuplicates dialect supports option is enhanced to include
falseas valid value for dialects not supporting it.ignoreDuplicates:
| false /* Not supported /
| string / dialect specific words for INSERT IGNORE or DO NOTHING */;
Ex:
MariaDb: ' IGNORE' → string .
Postgres: '' → string
Oracle, db2, ibmi: false → Not supported.
updateOnDuplicate:
updateOnDuplicate: '', is set for ibmi so that dialect.supports.inserts.updateOnDuplicate can be used
Unit tests:
Updated to use $sequelize_1, $sequelize_2, ... placeholders to match the positional bind style used in SQL generation.
Miscellaneous:
Updated copyright year.
List of Breaking Changes
Summary by CodeRabbit
New Features
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.