relq 1.0.102 → 1.0.104

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.
@@ -433,52 +433,58 @@ async function runPull(config, projectRoot, opts = {}) {
433
433
  }
434
434
  console.log('');
435
435
  if (schemaExists && localSnapshot && !force) {
436
+ const snapshotTables = Object.values(localSnapshot.tables || {});
436
437
  const localForCompare = {
437
- extensions: localSnapshot.extensions?.map(e => e.name) || [],
438
+ extensions: Array.isArray(localSnapshot.extensions)
439
+ ? localSnapshot.extensions
440
+ : [],
438
441
  enums: localSnapshot.enums || [],
439
- domains: localSnapshot.domains?.map(d => ({
442
+ domains: (localSnapshot.domains || []).map((d) => ({
440
443
  name: d.name,
441
444
  baseType: d.baseType,
442
- isNotNull: d.notNull,
443
- defaultValue: d.default,
444
- checkExpression: d.check,
445
- })) || [],
445
+ isNotNull: d.isNotNull ?? d.notNull,
446
+ defaultValue: d.defaultValue ?? d.default,
447
+ checkExpression: d.checkExpression ?? d.check,
448
+ })),
446
449
  compositeTypes: localSnapshot.compositeTypes || [],
447
450
  sequences: localSnapshot.sequences || [],
448
- tables: localSnapshot.tables.map(t => ({
451
+ tables: snapshotTables.map(t => ({
449
452
  name: t.name,
450
453
  schema: t.schema,
451
- columns: t.columns.map(c => ({
454
+ columns: Object.values(t.columns || {}).map((c) => ({
452
455
  name: c.name,
453
- dataType: c.type,
454
- isNullable: c.nullable,
455
- defaultValue: c.default,
456
- isPrimaryKey: c.primaryKey,
457
- isUnique: c.unique,
456
+ dataType: c.dataType ?? c.type,
457
+ isNullable: c.isNullable ?? c.nullable ?? false,
458
+ defaultValue: c.defaultValue ?? c.default ?? null,
459
+ isPrimaryKey: c.isPrimaryKey ?? c.primaryKey ?? false,
460
+ isUnique: c.isUnique ?? c.unique ?? false,
461
+ maxLength: c.maxLength ?? null,
462
+ precision: c.precision ?? null,
463
+ scale: c.scale ?? null,
458
464
  comment: c.comment,
459
465
  })),
460
- indexes: t.indexes.map(i => ({
466
+ indexes: Object.values(t.indexes || {}).map((i) => ({
461
467
  name: i.name,
462
468
  columns: i.columns,
463
- isUnique: i.unique,
469
+ isUnique: i.isUnique ?? i.unique ?? false,
464
470
  type: i.type,
465
471
  comment: i.comment,
466
472
  })),
467
- constraints: t.constraints || [],
473
+ constraints: Object.values(t.constraints || {}),
468
474
  isPartitioned: t.isPartitioned,
469
475
  partitionType: t.partitionType,
470
476
  partitionKey: t.partitionKey,
471
477
  comment: t.comment,
472
478
  })),
473
479
  functions: localSnapshot.functions || [],
474
- triggers: (localSnapshot.triggers || []).map(t => ({
480
+ triggers: (localSnapshot.triggers || []).map((t) => ({
475
481
  name: t.name,
476
- tableName: t.table,
477
- event: t.events?.[0] || 'UPDATE',
482
+ tableName: t.tableName ?? t.table,
483
+ event: t.event ?? t.events?.[0] ?? 'UPDATE',
478
484
  timing: t.timing,
479
485
  forEach: t.forEach || 'STATEMENT',
480
486
  functionName: t.functionName,
481
- definition: '',
487
+ definition: t.definition || '',
482
488
  isEnabled: true,
483
489
  })),
484
490
  };
@@ -480,7 +480,22 @@ async function runPush(config, projectRoot, opts = {}) {
480
480
  + comparison.removed.views.length + comparison.removed.functions.length
481
481
  + comparison.removed.triggers.length + comparison.removed.extensions.length;
482
482
  const ddlModified = comparison.modified.enums.length;
483
- console.log(` ${colors_1.colors.green(`${s.tablesAdded + s.columnsAdded + ddlAdded} added`)}, ${colors_1.colors.yellow(`${s.tablesModified + s.columnsModified + ddlModified} modified`)}, ${colors_1.colors.red(`${s.tablesRemoved + s.columnsRemoved + ddlRemoved} removed`)}`);
483
+ const totalAdded = s.tablesAdded + s.columnsAdded + s.indexesAdded + ddlAdded;
484
+ const totalModified = s.tablesModified + s.columnsModified + ddlModified;
485
+ const totalRemoved = s.tablesRemoved + s.columnsRemoved + s.indexesRemoved + ddlRemoved;
486
+ const parts = [];
487
+ if (totalAdded > 0 || totalModified > 0 || totalRemoved > 0) {
488
+ if (totalAdded > 0)
489
+ parts.push(colors_1.colors.green(`${totalAdded} added`));
490
+ if (totalModified > 0)
491
+ parts.push(colors_1.colors.yellow(`${totalModified} modified`));
492
+ if (totalRemoved > 0)
493
+ parts.push(colors_1.colors.red(`${totalRemoved} removed`));
494
+ }
495
+ else {
496
+ parts.push('no changes');
497
+ }
498
+ console.log(` ${parts.join(', ')}`);
484
499
  console.log('');
485
500
  }
486
501
  catch (err) {
@@ -415,6 +415,25 @@ function generateColumnModification(tableName, columnName, changes) {
415
415
  }
416
416
  break;
417
417
  }
418
+ case 'precision':
419
+ case 'scale': {
420
+ if (change.field === 'precision') {
421
+ const newPrec = change.to;
422
+ const scaleChange = changes.find(c => c.field === 'scale');
423
+ const newScale = scaleChange ? scaleChange.to : undefined;
424
+ const oldPrec = change.from;
425
+ const oldScale = scaleChange ? scaleChange.from : undefined;
426
+ const newFullType = newPrec != null
427
+ ? (newScale != null ? `NUMERIC(${newPrec}, ${newScale})` : `NUMERIC(${newPrec})`)
428
+ : 'NUMERIC';
429
+ const oldFullType = oldPrec != null
430
+ ? (oldScale != null ? `NUMERIC(${oldPrec}, ${oldScale})` : `NUMERIC(${oldPrec})`)
431
+ : 'NUMERIC';
432
+ upSQL.push(`ALTER TABLE "${tableName}" ALTER COLUMN "${columnName}" TYPE ${newFullType};`);
433
+ downSQL.push(`ALTER TABLE "${tableName}" ALTER COLUMN "${columnName}" TYPE ${oldFullType};`);
434
+ }
435
+ break;
436
+ }
418
437
  }
419
438
  }
420
439
  return { upSQL, downSQL };
@@ -484,7 +503,19 @@ function buildParsedConstraintDef(con) {
484
503
  }
485
504
  }
486
505
  function generateParsedColumnDef(col) {
487
- const parts = [`"${col.name}"`, col.type];
506
+ let typeName = col.type;
507
+ if (col.typeParams?.length != null) {
508
+ typeName = `${typeName}(${col.typeParams.length})`;
509
+ }
510
+ else if (col.typeParams?.precision != null) {
511
+ typeName = col.typeParams.scale != null
512
+ ? `${typeName}(${col.typeParams.precision}, ${col.typeParams.scale})`
513
+ : `${typeName}(${col.typeParams.precision})`;
514
+ }
515
+ if (col.isArray) {
516
+ typeName = `${typeName}[]`;
517
+ }
518
+ const parts = [`"${col.name}"`, typeName];
488
519
  if (col.isPrimaryKey) {
489
520
  parts.push('PRIMARY KEY');
490
521
  }
@@ -1072,6 +1072,21 @@ function compareColumnProperties(oldCol, newCol) {
1072
1072
  if (oldCol.defaultValue !== newCol.defaultValue) {
1073
1073
  changes.push({ field: 'default', from: oldCol.defaultValue, to: newCol.defaultValue });
1074
1074
  }
1075
+ const oldLength = oldCol.typeParams?.length;
1076
+ const newLength = newCol.typeParams?.length;
1077
+ if (oldLength !== newLength) {
1078
+ changes.push({ field: 'length', from: oldLength, to: newLength });
1079
+ }
1080
+ const oldPrecision = oldCol.typeParams?.precision;
1081
+ const newPrecision = newCol.typeParams?.precision;
1082
+ if (oldPrecision !== newPrecision) {
1083
+ changes.push({ field: 'precision', from: oldPrecision, to: newPrecision });
1084
+ }
1085
+ const oldScale = oldCol.typeParams?.scale;
1086
+ const newScale = newCol.typeParams?.scale;
1087
+ if (oldScale !== newScale) {
1088
+ changes.push({ field: 'scale', from: oldScale, to: newScale });
1089
+ }
1075
1090
  return changes;
1076
1091
  }
1077
1092
  function compareTableIndexes(oldTable, newTable, tableName, result) {
@@ -397,52 +397,58 @@ export async function runPull(config, projectRoot, opts = {}) {
397
397
  }
398
398
  console.log('');
399
399
  if (schemaExists && localSnapshot && !force) {
400
+ const snapshotTables = Object.values(localSnapshot.tables || {});
400
401
  const localForCompare = {
401
- extensions: localSnapshot.extensions?.map(e => e.name) || [],
402
+ extensions: Array.isArray(localSnapshot.extensions)
403
+ ? localSnapshot.extensions
404
+ : [],
402
405
  enums: localSnapshot.enums || [],
403
- domains: localSnapshot.domains?.map(d => ({
406
+ domains: (localSnapshot.domains || []).map((d) => ({
404
407
  name: d.name,
405
408
  baseType: d.baseType,
406
- isNotNull: d.notNull,
407
- defaultValue: d.default,
408
- checkExpression: d.check,
409
- })) || [],
409
+ isNotNull: d.isNotNull ?? d.notNull,
410
+ defaultValue: d.defaultValue ?? d.default,
411
+ checkExpression: d.checkExpression ?? d.check,
412
+ })),
410
413
  compositeTypes: localSnapshot.compositeTypes || [],
411
414
  sequences: localSnapshot.sequences || [],
412
- tables: localSnapshot.tables.map(t => ({
415
+ tables: snapshotTables.map(t => ({
413
416
  name: t.name,
414
417
  schema: t.schema,
415
- columns: t.columns.map(c => ({
418
+ columns: Object.values(t.columns || {}).map((c) => ({
416
419
  name: c.name,
417
- dataType: c.type,
418
- isNullable: c.nullable,
419
- defaultValue: c.default,
420
- isPrimaryKey: c.primaryKey,
421
- isUnique: c.unique,
420
+ dataType: c.dataType ?? c.type,
421
+ isNullable: c.isNullable ?? c.nullable ?? false,
422
+ defaultValue: c.defaultValue ?? c.default ?? null,
423
+ isPrimaryKey: c.isPrimaryKey ?? c.primaryKey ?? false,
424
+ isUnique: c.isUnique ?? c.unique ?? false,
425
+ maxLength: c.maxLength ?? null,
426
+ precision: c.precision ?? null,
427
+ scale: c.scale ?? null,
422
428
  comment: c.comment,
423
429
  })),
424
- indexes: t.indexes.map(i => ({
430
+ indexes: Object.values(t.indexes || {}).map((i) => ({
425
431
  name: i.name,
426
432
  columns: i.columns,
427
- isUnique: i.unique,
433
+ isUnique: i.isUnique ?? i.unique ?? false,
428
434
  type: i.type,
429
435
  comment: i.comment,
430
436
  })),
431
- constraints: t.constraints || [],
437
+ constraints: Object.values(t.constraints || {}),
432
438
  isPartitioned: t.isPartitioned,
433
439
  partitionType: t.partitionType,
434
440
  partitionKey: t.partitionKey,
435
441
  comment: t.comment,
436
442
  })),
437
443
  functions: localSnapshot.functions || [],
438
- triggers: (localSnapshot.triggers || []).map(t => ({
444
+ triggers: (localSnapshot.triggers || []).map((t) => ({
439
445
  name: t.name,
440
- tableName: t.table,
441
- event: t.events?.[0] || 'UPDATE',
446
+ tableName: t.tableName ?? t.table,
447
+ event: t.event ?? t.events?.[0] ?? 'UPDATE',
442
448
  timing: t.timing,
443
449
  forEach: t.forEach || 'STATEMENT',
444
450
  functionName: t.functionName,
445
- definition: '',
451
+ definition: t.definition || '',
446
452
  isEnabled: true,
447
453
  })),
448
454
  };
@@ -444,7 +444,22 @@ export async function runPush(config, projectRoot, opts = {}) {
444
444
  + comparison.removed.views.length + comparison.removed.functions.length
445
445
  + comparison.removed.triggers.length + comparison.removed.extensions.length;
446
446
  const ddlModified = comparison.modified.enums.length;
447
- console.log(` ${colors.green(`${s.tablesAdded + s.columnsAdded + ddlAdded} added`)}, ${colors.yellow(`${s.tablesModified + s.columnsModified + ddlModified} modified`)}, ${colors.red(`${s.tablesRemoved + s.columnsRemoved + ddlRemoved} removed`)}`);
447
+ const totalAdded = s.tablesAdded + s.columnsAdded + s.indexesAdded + ddlAdded;
448
+ const totalModified = s.tablesModified + s.columnsModified + ddlModified;
449
+ const totalRemoved = s.tablesRemoved + s.columnsRemoved + s.indexesRemoved + ddlRemoved;
450
+ const parts = [];
451
+ if (totalAdded > 0 || totalModified > 0 || totalRemoved > 0) {
452
+ if (totalAdded > 0)
453
+ parts.push(colors.green(`${totalAdded} added`));
454
+ if (totalModified > 0)
455
+ parts.push(colors.yellow(`${totalModified} modified`));
456
+ if (totalRemoved > 0)
457
+ parts.push(colors.red(`${totalRemoved} removed`));
458
+ }
459
+ else {
460
+ parts.push('no changes');
461
+ }
462
+ console.log(` ${parts.join(', ')}`);
448
463
  console.log('');
449
464
  }
450
465
  catch (err) {
@@ -373,6 +373,25 @@ function generateColumnModification(tableName, columnName, changes) {
373
373
  }
374
374
  break;
375
375
  }
376
+ case 'precision':
377
+ case 'scale': {
378
+ if (change.field === 'precision') {
379
+ const newPrec = change.to;
380
+ const scaleChange = changes.find(c => c.field === 'scale');
381
+ const newScale = scaleChange ? scaleChange.to : undefined;
382
+ const oldPrec = change.from;
383
+ const oldScale = scaleChange ? scaleChange.from : undefined;
384
+ const newFullType = newPrec != null
385
+ ? (newScale != null ? `NUMERIC(${newPrec}, ${newScale})` : `NUMERIC(${newPrec})`)
386
+ : 'NUMERIC';
387
+ const oldFullType = oldPrec != null
388
+ ? (oldScale != null ? `NUMERIC(${oldPrec}, ${oldScale})` : `NUMERIC(${oldPrec})`)
389
+ : 'NUMERIC';
390
+ upSQL.push(`ALTER TABLE "${tableName}" ALTER COLUMN "${columnName}" TYPE ${newFullType};`);
391
+ downSQL.push(`ALTER TABLE "${tableName}" ALTER COLUMN "${columnName}" TYPE ${oldFullType};`);
392
+ }
393
+ break;
394
+ }
376
395
  }
377
396
  }
378
397
  return { upSQL, downSQL };
@@ -442,7 +461,19 @@ function buildParsedConstraintDef(con) {
442
461
  }
443
462
  }
444
463
  function generateParsedColumnDef(col) {
445
- const parts = [`"${col.name}"`, col.type];
464
+ let typeName = col.type;
465
+ if (col.typeParams?.length != null) {
466
+ typeName = `${typeName}(${col.typeParams.length})`;
467
+ }
468
+ else if (col.typeParams?.precision != null) {
469
+ typeName = col.typeParams.scale != null
470
+ ? `${typeName}(${col.typeParams.precision}, ${col.typeParams.scale})`
471
+ : `${typeName}(${col.typeParams.precision})`;
472
+ }
473
+ if (col.isArray) {
474
+ typeName = `${typeName}[]`;
475
+ }
476
+ const parts = [`"${col.name}"`, typeName];
446
477
  if (col.isPrimaryKey) {
447
478
  parts.push('PRIMARY KEY');
448
479
  }
@@ -1061,6 +1061,21 @@ function compareColumnProperties(oldCol, newCol) {
1061
1061
  if (oldCol.defaultValue !== newCol.defaultValue) {
1062
1062
  changes.push({ field: 'default', from: oldCol.defaultValue, to: newCol.defaultValue });
1063
1063
  }
1064
+ const oldLength = oldCol.typeParams?.length;
1065
+ const newLength = newCol.typeParams?.length;
1066
+ if (oldLength !== newLength) {
1067
+ changes.push({ field: 'length', from: oldLength, to: newLength });
1068
+ }
1069
+ const oldPrecision = oldCol.typeParams?.precision;
1070
+ const newPrecision = newCol.typeParams?.precision;
1071
+ if (oldPrecision !== newPrecision) {
1072
+ changes.push({ field: 'precision', from: oldPrecision, to: newPrecision });
1073
+ }
1074
+ const oldScale = oldCol.typeParams?.scale;
1075
+ const newScale = newCol.typeParams?.scale;
1076
+ if (oldScale !== newScale) {
1077
+ changes.push({ field: 'scale', from: oldScale, to: newScale });
1078
+ }
1064
1079
  return changes;
1065
1080
  }
1066
1081
  function compareTableIndexes(oldTable, newTable, tableName, result) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relq",
3
- "version": "1.0.102",
3
+ "version": "1.0.104",
4
4
  "description": "The Fully-Typed PostgreSQL ORM for TypeScript",
5
5
  "author": "Olajide Mathew O. <olajide.mathew@yuniq.solutions>",
6
6
  "license": "MIT",