relq 1.0.102 → 1.0.103

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) {
@@ -484,7 +484,19 @@ function buildParsedConstraintDef(con) {
484
484
  }
485
485
  }
486
486
  function generateParsedColumnDef(col) {
487
- const parts = [`"${col.name}"`, col.type];
487
+ let typeName = col.type;
488
+ if (col.typeParams?.length != null) {
489
+ typeName = `${typeName}(${col.typeParams.length})`;
490
+ }
491
+ else if (col.typeParams?.precision != null) {
492
+ typeName = col.typeParams.scale != null
493
+ ? `${typeName}(${col.typeParams.precision}, ${col.typeParams.scale})`
494
+ : `${typeName}(${col.typeParams.precision})`;
495
+ }
496
+ if (col.isArray) {
497
+ typeName = `${typeName}[]`;
498
+ }
499
+ const parts = [`"${col.name}"`, typeName];
488
500
  if (col.isPrimaryKey) {
489
501
  parts.push('PRIMARY KEY');
490
502
  }
@@ -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) {
@@ -442,7 +442,19 @@ function buildParsedConstraintDef(con) {
442
442
  }
443
443
  }
444
444
  function generateParsedColumnDef(col) {
445
- const parts = [`"${col.name}"`, col.type];
445
+ let typeName = col.type;
446
+ if (col.typeParams?.length != null) {
447
+ typeName = `${typeName}(${col.typeParams.length})`;
448
+ }
449
+ else if (col.typeParams?.precision != null) {
450
+ typeName = col.typeParams.scale != null
451
+ ? `${typeName}(${col.typeParams.precision}, ${col.typeParams.scale})`
452
+ : `${typeName}(${col.typeParams.precision})`;
453
+ }
454
+ if (col.isArray) {
455
+ typeName = `${typeName}[]`;
456
+ }
457
+ const parts = [`"${col.name}"`, typeName];
446
458
  if (col.isPrimaryKey) {
447
459
  parts.push('PRIMARY KEY');
448
460
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relq",
3
- "version": "1.0.102",
3
+ "version": "1.0.103",
4
4
  "description": "The Fully-Typed PostgreSQL ORM for TypeScript",
5
5
  "author": "Olajide Mathew O. <olajide.mathew@yuniq.solutions>",
6
6
  "license": "MIT",