Skip to content

feat(oracle): add oracle support - #18050

Merged
WikiRik merged 262 commits into
sequelize:mainfrom
sudarshan12s:oracledbv7changes
Jan 14, 2026
Merged

WikiRik merged 262 commits into
sequelize:mainfrom
sudarshan12s:oracledbv7changes

Conversation

@sudarshan12s

@sudarshan12s sudarshan12s commented Nov 7, 2025 •

Copy link
Copy Markdown
Contributor

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description of Changes

This change fixes CI issues on top of PR #17403.

Major updates:

  • Oracle upsert:
    The Oracle dialect generates both updateQuery and insertQuery, combining them into a single PL/SQL block with binds.
    To ensure bind numbering continues correctly between the two queries, createBindParamGenerator was updated to accept the dialect parameter and continue numbering based on Object.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 false as 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

    • Official Oracle dialect added with full runtime support (connection, query execution, and upsert behavior) via a new package.
  • Tests

    • Extensive Oracle-focused unit and integration tests plus helpers; CI matrix updated to run Oracle tests.
  • Chores

    • Local Oracle developer tooling and npm scripts added, plus Docker Compose and lifecycle scripts for running local Oracle test instances.

✏️ Tip: You can customize this high-level summary in your review settings.

…d showConstraints and test cases related to that

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

  1. Incorrect role quoting: Oracle predefined role names like CONNECT should be granted without quotes. The expectation should use GRANT CONNECT TO "mySchema" instead of GRANT "CONNECT" TO "mySchema" (and similarly for other system privileges).

  2. 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: comment is only supported by Snowflake, so Oracle should reject it
  • Line 74: ifNotExists is explicitly rejected by Oracle
  • Line 84: replace is 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 requires COMMIT and ROLLBACK without the TRANSACTION keyword. Since the Oracle dialect does not set connectionTransactionMethods: 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 EXISTS in removeConstraintQuery is still present despite being marked resolved.

The past review comment flagged that Oracle does not support IF EXISTS in DROP CONSTRAINT clauses (line 150), marked as "✅ Addressed in commit 8454ae2." However, the code still emits IF EXISTS when options?.ifExists is true for sys-prefixed constraints, which will cause ORA-11557 runtime errors.

Either validate and reject the ifExists option 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 splicing options.indexes.

Splicing array elements while iterating idxToDelete in forward order causes index misalignment. After the first splice, 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 filter to 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 in attributeToSQL.

Line 898 compares attribute.type === 'DOUBLE' (strict equality with a string), but attribute.type is a DataType class instance. This condition is unreachable dead code and inconsistent with other branches that use instanceof (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 of null and non-null values for an auto-increment column is only detected when the last row is null. 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: getDefaultSchema will throw in non-replication setups.

Line 110 accesses this.sequelize.options.replication.write.username without safe optional chaining on replication or write. In default (non-replication) configurations, replication or write will be undefined, causing a runtime error before the optional chaining on username is 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 in DialectSupports use /* */ 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 OracleDialectOptions interface 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

📥 Commits

Reviewing files that changed from the base of the PR and between f0517e9 and a2e1522.

📒 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.ts
  • packages/oracle/src/query-generator-typescript.internal.ts
  • packages/oracle/src/query-generator.js
  • packages/core/src/abstract-dialect/dialect.ts
  • packages/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.ts
  • packages/oracle/src/query-generator-typescript.internal.ts
  • packages/oracle/src/query-generator.js
  • packages/core/src/abstract-dialect/dialect.ts
  • packages/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.ts
  • packages/oracle/src/query-generator-typescript.internal.ts
  • packages/oracle/src/query-generator.js
  • packages/core/src/abstract-dialect/dialect.ts
  • packages/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.ts
  • packages/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.js
  • packages/core/src/abstract-dialect/dialect.ts
  • packages/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.ts
  • packages/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 returnIntoValues and topLevelOrderByRequired capability 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 | string properly 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 false for both properties are appropriate, requiring Oracle (and any other dialect needing these features) to explicitly opt-in.


471-474: LGTM!

Defaulting concurrentDropConstraints: true maintains backward compatibility for existing dialects while allowing Oracle to override this to false in its dialect implementation.

@sudarshan12s

Copy link
Copy Markdown
Contributor Author

I think these should be the final comments

Thanks. I have addressed all the comments.

@sudarshan12s
sudarshan12s requested a review from WikiRik December 18, 2025 13:57
@sharadraju

Copy link
Copy Markdown

@WikiRik Wish you a very Happy New Year!
Thank you for the diligent reviews. Can you take one final look and merge this, if everything is fine.

@WikiRik

WikiRik commented Jan 14, 2026

Copy link
Copy Markdown
Member

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!

@WikiRik
WikiRik enabled auto-merge (squash) January 14, 2026 11:29
@WikiRik WikiRik changed the title feat(oracle): Add support for oracle dialect in v7 feat(oracle): add oracle support Jan 14, 2026
@WikiRik
WikiRik merged commit 3a92f26 into sequelize:main Jan 14, 2026
54 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 11, 2026
4 of 5 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Aug 13, 2026
5 tasks done
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