@mikro-orm/oracledb 7.3.0-dev.1 → 7.3.0-dev.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,7 +58,9 @@ export class OracleQueryBuilder extends QueryBuilder {
58
58
  }
59
59
  if (this.type === QueryType.INSERT) {
60
60
  const returningProps = meta.hydrateProps
61
- .filter(prop => prop.returning || (prop.persist !== false && ((prop.primary && prop.autoincrement) || prop.defaultRaw)))
61
+ .filter(prop => prop.returning || (prop.persist !== false && (prop.autoincrement || prop.generated || prop.defaultRaw)))
62
+ // a TPT table can only return its own columns
63
+ .filter(prop => meta.inheritanceType !== 'tpt' || prop.primary || meta.ownProps.some(p => p.name === prop.name))
62
64
  .filter(prop => !(prop.fieldNames[0] in arr[0]) || isRaw(arr[0][prop.fieldNames[0]]));
63
65
  if (returningProps.length > 0) {
64
66
  qb.returning(returningProps.map(prop => [prop.fieldNames[0], prop.runtimeType]));
@@ -369,8 +369,10 @@ export class OracleSchemaGenerator extends SchemaGenerator {
369
369
  .join('.');
370
370
  // Use DELETE instead of TRUNCATE to avoid ORA-02266 (FK constraint check regardless of data)
371
371
  stmts.push(`begin execute immediate 'delete from ${quoted}'; exception when others then if sqlcode != -942 then raise; end if; end;`);
372
- for (const pk of meta.getPrimaryProps().filter(p => p.autoincrement)) {
373
- stmts.push(`begin execute immediate 'alter table ${quoted} modify ${this.platform.quoteIdentifier(pk.fieldNames[0])} generated by default as identity (start with limit value)'; exception when others then null; end;`);
372
+ // non-PK identity columns are only reset when they declare `sequence`
373
+ for (const prop of meta.props.filter(p => p.autoincrement && (p.primary || p.sequence))) {
374
+ const startWith = prop.sequence?.startWith ?? 'limit value';
375
+ stmts.push(`begin execute immediate 'alter table ${quoted} modify ${this.platform.quoteIdentifier(prop.fieldNames[0])} generated by default as identity (start with ${startWith})'; exception when others then null; end;`);
374
376
  }
375
377
  }
376
378
  /* v8 ignore next 5: empty stmts branch */
@@ -145,9 +145,12 @@ export class OracleSchemaHelper extends SchemaHelper {
145
145
  atc.data_length as data_length,
146
146
  atc.identity_column as is_identity,
147
147
  atc.column_id as ordinal_position,
148
- atc.collation as collation_name
148
+ atc.collation as collation_name,
149
+ regexp_substr(aic.identity_options, 'START WITH: (-?\\d+)', 1, 1, null, 1) as sequence_start,
150
+ regexp_substr(aic.identity_options, 'INCREMENT BY: (-?\\d+)', 1, 1, null, 1) as sequence_increment
149
151
  from all_tab_cols atc
150
152
  left join all_col_comments acc on atc.owner = acc.owner and atc.table_name = acc.table_name and atc.column_name = acc.column_name
153
+ left join all_tab_identity_cols aic on atc.owner = aic.owner and atc.table_name = aic.table_name and atc.column_name = aic.column_name
151
154
  where atc.hidden_column = 'NO'
152
155
  and (${[...tablesBySchemas.entries()].map(([schema, tables]) => `(atc.table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(', ')}) and atc.owner = ${this.platform.quoteValue(schema)})`).join(' or ')})
153
156
  order by atc.owner, atc.table_name, atc.column_id`;
@@ -198,6 +201,7 @@ export class OracleSchemaHelper extends SchemaHelper {
198
201
  default: increments ? undefined : this.wrap(defaultValue, mappedType),
199
202
  nullable: col.is_nullable === 'Y',
200
203
  autoincrement: increments,
204
+ sequence: increments ? this.getIntrospectedSequence(col.sequence_start, col.sequence_increment) : undefined,
201
205
  precision: col.numeric_precision,
202
206
  scale: col.numeric_scale,
203
207
  comment: col.column_comment,
@@ -234,17 +238,12 @@ export class OracleSchemaHelper extends SchemaHelper {
234
238
  const isPrimary = index.constraint_type === 'P';
235
239
  const isUniqueConstraint = index.constraint_type === 'U';
236
240
  const isConstraintIndex = isPrimary || isUniqueConstraint;
237
- // Skip indexes that back PRIMARY KEY constraints - they're handled as part of the table definition
238
- // and should not be managed as separate indexes
239
- if (isPrimary) {
240
- continue;
241
- }
242
241
  const partialMatch = typeof index.expression === 'string' ? OracleSchemaHelper.PARTIAL_INDEX_RE.exec(index.expression) : null;
243
242
  const indexDef = {
244
243
  columnNames: [partialMatch ? partialMatch[2] : index.column_name],
245
244
  keyName: index.index_name,
246
245
  unique: index.is_unique === 'YES',
247
- primary: false,
246
+ primary: isPrimary,
248
247
  constraint: isConstraintIndex || index.is_unique === 'YES',
249
248
  };
250
249
  /* v8 ignore start: function-based (non-partial) index branches */
@@ -412,7 +411,8 @@ export class OracleSchemaHelper extends SchemaHelper {
412
411
  const changedTypes = Object.values(tableDiff.changedColumns).filter(col => col.changedProperties.has('type'));
413
412
  for (const col of changedTypes) {
414
413
  for (const index of indexes) {
415
- if (index.columnNames.includes(col.column.name)) {
414
+ // the index backing the primary key can't be dropped, the key constraint stays in place
415
+ if (!index.primary && index.columnNames.includes(col.column.name)) {
416
416
  ret.push(this.getDropIndexSQL(name, index));
417
417
  }
418
418
  }
@@ -430,7 +430,7 @@ export class OracleSchemaHelper extends SchemaHelper {
430
430
  const changedTypes = Object.values(tableDiff.changedColumns).filter(col => col.changedProperties.has('type'));
431
431
  for (const col of changedTypes) {
432
432
  for (const index of indexes) {
433
- if (index.columnNames.includes(col.column.name)) {
433
+ if (!index.primary && index.columnNames.includes(col.column.name)) {
434
434
  this.append(ret, this.getCreateIndexSQL(name, index));
435
435
  }
436
436
  }
@@ -457,8 +457,9 @@ export class OracleSchemaHelper extends SchemaHelper {
457
457
  return `drop index ${this.quote(index.keyName)}`;
458
458
  }
459
459
  dropIndex(table, index, oldIndexName = index.keyName) {
460
+ // the primary key constraint name is system generated unless named explicitly
460
461
  if (index.primary) {
461
- return `alter table ${this.quote(table)} drop constraint ${this.quote(oldIndexName)}`;
462
+ return `alter table ${this.quote(table)} drop primary key`;
462
463
  }
463
464
  return `drop index ${this.quote(oldIndexName)}`;
464
465
  }
@@ -496,7 +497,8 @@ export class OracleSchemaHelper extends SchemaHelper {
496
497
  const columnType = column.generated ? `as ${column.generated}` : column.type;
497
498
  const col = [this.quote(column.name), columnType];
498
499
  Utils.runIfNotEmpty(() => col.push(this.getCollateSQL(column.collation)), column.collation);
499
- Utils.runIfNotEmpty(() => col.push('generated by default as identity'), column.autoincrement);
500
+ const sequenceOptions = this.getSequenceOptionsSQL(column);
501
+ Utils.runIfNotEmpty(() => col.push(`generated by default as identity${sequenceOptions ? ` (${sequenceOptions})` : ''}`), column.autoincrement);
500
502
  /* v8 ignore next 3: default value branch */
501
503
  const useDefault = changedProperties
502
504
  ? false
@@ -568,7 +570,7 @@ export class OracleSchemaHelper extends SchemaHelper {
568
570
  }
569
571
  createIndex(index, table, createPrimary = false) {
570
572
  if (index.primary) {
571
- return '';
573
+ return createPrimary ? super.createIndex(index, table, true) : '';
572
574
  }
573
575
  if (index.expression) {
574
576
  return index.expression;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/oracledb",
3
- "version": "7.3.0-dev.1",
3
+ "version": "7.3.0-dev.11",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite, MSSQL and Oracle databases.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -42,15 +42,15 @@
42
42
  "copy": "node ../../scripts/copy.mjs"
43
43
  },
44
44
  "dependencies": {
45
- "@mikro-orm/sql": "7.3.0-dev.1",
45
+ "@mikro-orm/sql": "7.3.0-dev.11",
46
46
  "kysely": "0.29.6",
47
47
  "oracledb": "7.0.1"
48
48
  },
49
49
  "devDependencies": {
50
- "@mikro-orm/core": "^7.2.1"
50
+ "@mikro-orm/core": "^7.2.2"
51
51
  },
52
52
  "peerDependencies": {
53
- "@mikro-orm/core": "7.3.0-dev.1"
53
+ "@mikro-orm/core": "7.3.0-dev.11"
54
54
  },
55
55
  "engines": {
56
56
  "node": ">= 22.17.0"