relq 1.0.26 → 1.0.27

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.
@@ -375,10 +375,92 @@ async function pullCommand(context) {
375
375
  (0, cli_utils_1.fatal)('You have unresolved merge conflicts', `Use ${cli_utils_1.colors.cyan('relq resolve')} to see and resolve conflicts\nOr use ${cli_utils_1.colors.cyan('relq pull --force')} to overwrite local`);
376
376
  }
377
377
  if (schemaExists && localSnapshot && !force) {
378
- const localTables = new Set(localSnapshot.tables.map(t => t.name));
379
- const remoteTables = new Set(currentSchema.tables.map(t => t.name));
380
- const added = [...remoteTables].filter(t => !localTables.has(t));
381
- const removed = [...localTables].filter(t => !remoteTables.has(t));
378
+ const localForCompare = {
379
+ extensions: localSnapshot.extensions?.map(e => e.name) || [],
380
+ enums: localSnapshot.enums || [],
381
+ domains: localSnapshot.domains?.map(d => ({
382
+ name: d.name,
383
+ baseType: d.baseType,
384
+ isNotNull: d.notNull,
385
+ defaultValue: d.default,
386
+ checkExpression: d.check,
387
+ })) || [],
388
+ compositeTypes: localSnapshot.compositeTypes || [],
389
+ sequences: localSnapshot.sequences || [],
390
+ tables: localSnapshot.tables.map(t => ({
391
+ name: t.name,
392
+ schema: t.schema,
393
+ columns: t.columns.map(c => ({
394
+ name: c.name,
395
+ dataType: c.type,
396
+ isNullable: c.nullable,
397
+ defaultValue: c.default,
398
+ isPrimaryKey: c.primaryKey,
399
+ isUnique: c.unique,
400
+ comment: c.comment,
401
+ })),
402
+ indexes: t.indexes.map(i => ({
403
+ name: i.name,
404
+ columns: i.columns,
405
+ isUnique: i.unique,
406
+ type: i.type,
407
+ comment: i.comment,
408
+ })),
409
+ constraints: t.constraints || [],
410
+ isPartitioned: t.isPartitioned,
411
+ partitionType: t.partitionType,
412
+ partitionKey: t.partitionKey,
413
+ comment: t.comment,
414
+ })),
415
+ functions: localSnapshot.functions || [],
416
+ triggers: localSnapshot.triggers || [],
417
+ };
418
+ const remoteForCompare = {
419
+ extensions: dbSchema.extensions || [],
420
+ enums: filteredEnums || [],
421
+ domains: filteredDomains?.map(d => ({
422
+ name: d.name,
423
+ baseType: d.baseType,
424
+ isNotNull: d.isNotNull,
425
+ defaultValue: d.defaultValue,
426
+ checkExpression: d.checkExpression,
427
+ })) || [],
428
+ compositeTypes: filteredCompositeTypes || [],
429
+ sequences: [],
430
+ tables: filteredTables.map(t => ({
431
+ name: t.name,
432
+ schema: t.schema,
433
+ columns: t.columns.map(c => ({
434
+ name: c.name,
435
+ dataType: c.dataType,
436
+ isNullable: c.isNullable,
437
+ defaultValue: c.defaultValue,
438
+ isPrimaryKey: c.isPrimaryKey,
439
+ isUnique: c.isUnique,
440
+ comment: c.comment,
441
+ })),
442
+ indexes: t.indexes.map(i => ({
443
+ name: i.name,
444
+ columns: i.columns,
445
+ isUnique: i.isUnique,
446
+ type: i.type,
447
+ comment: i.comment,
448
+ })),
449
+ constraints: t.constraints || [],
450
+ isPartitioned: t.isPartitioned,
451
+ partitionType: t.partitionType,
452
+ partitionKey: t.partitionKey,
453
+ comment: t.comment,
454
+ })),
455
+ functions: filteredFunctions || [],
456
+ triggers: filteredTriggers || [],
457
+ };
458
+ const allChanges = (0, schema_comparator_1.compareSchemas)(localForCompare, remoteForCompare);
459
+ const tablesAdded = allChanges.filter(c => c.type === 'CREATE' && c.objectType === 'TABLE').length;
460
+ const tablesRemoved = allChanges.filter(c => c.type === 'DROP' && c.objectType === 'TABLE').length;
461
+ const columnsChanged = allChanges.filter(c => c.objectType === 'COLUMN').length;
462
+ const indexesChanged = allChanges.filter(c => c.objectType === 'INDEX').length;
463
+ const otherChanges = allChanges.filter(c => c.objectType !== 'TABLE' && c.objectType !== 'COLUMN' && c.objectType !== 'INDEX').length;
382
464
  const conflicts = detectObjectConflicts(localSnapshot, currentSchema);
383
465
  if (conflicts.length > 0 && !force) {
384
466
  const mergeState = {
@@ -400,17 +482,26 @@ async function pullCommand(context) {
400
482
  }
401
483
  (0, cli_utils_1.fatal)('Automatic merge failed; fix conflicts and then commit', `${cli_utils_1.colors.cyan('relq resolve --theirs <name>')} Take remote version\n${cli_utils_1.colors.cyan('relq resolve --all-theirs')} Take all remote\n${cli_utils_1.colors.cyan('relq pull --force')} Force overwrite local`);
402
484
  }
403
- if (added.length === 0 && removed.length === 0) {
485
+ if (allChanges.length === 0) {
404
486
  console.log('Already up to date with remote');
405
487
  console.log('');
406
488
  return;
407
489
  }
408
490
  console.log(`${cli_utils_1.colors.yellow('Remote has changes:')}`);
409
- if (added.length > 0) {
410
- console.log(` ${cli_utils_1.colors.green(`+${added.length}`)} tables added`);
491
+ if (tablesAdded > 0) {
492
+ console.log(` ${cli_utils_1.colors.green(`+${tablesAdded}`)} table(s) added`);
493
+ }
494
+ if (tablesRemoved > 0) {
495
+ console.log(` ${cli_utils_1.colors.red(`-${tablesRemoved}`)} table(s) removed`);
496
+ }
497
+ if (columnsChanged > 0) {
498
+ console.log(` ${cli_utils_1.colors.cyan(`~${columnsChanged}`)} column change(s)`);
499
+ }
500
+ if (indexesChanged > 0) {
501
+ console.log(` ${cli_utils_1.colors.cyan(`~${indexesChanged}`)} index change(s)`);
411
502
  }
412
- if (removed.length > 0) {
413
- console.log(` ${cli_utils_1.colors.red(`-${removed.length}`)} tables removed`);
503
+ if (otherChanges > 0) {
504
+ console.log(` ${cli_utils_1.colors.cyan(`~${otherChanges}`)} other change(s)`);
414
505
  }
415
506
  console.log('');
416
507
  const noAutoMerge = flags['no-auto-merge'] === true;
@@ -339,10 +339,92 @@ export async function pullCommand(context) {
339
339
  fatal('You have unresolved merge conflicts', `Use ${colors.cyan('relq resolve')} to see and resolve conflicts\nOr use ${colors.cyan('relq pull --force')} to overwrite local`);
340
340
  }
341
341
  if (schemaExists && localSnapshot && !force) {
342
- const localTables = new Set(localSnapshot.tables.map(t => t.name));
343
- const remoteTables = new Set(currentSchema.tables.map(t => t.name));
344
- const added = [...remoteTables].filter(t => !localTables.has(t));
345
- const removed = [...localTables].filter(t => !remoteTables.has(t));
342
+ const localForCompare = {
343
+ extensions: localSnapshot.extensions?.map(e => e.name) || [],
344
+ enums: localSnapshot.enums || [],
345
+ domains: localSnapshot.domains?.map(d => ({
346
+ name: d.name,
347
+ baseType: d.baseType,
348
+ isNotNull: d.notNull,
349
+ defaultValue: d.default,
350
+ checkExpression: d.check,
351
+ })) || [],
352
+ compositeTypes: localSnapshot.compositeTypes || [],
353
+ sequences: localSnapshot.sequences || [],
354
+ tables: localSnapshot.tables.map(t => ({
355
+ name: t.name,
356
+ schema: t.schema,
357
+ columns: t.columns.map(c => ({
358
+ name: c.name,
359
+ dataType: c.type,
360
+ isNullable: c.nullable,
361
+ defaultValue: c.default,
362
+ isPrimaryKey: c.primaryKey,
363
+ isUnique: c.unique,
364
+ comment: c.comment,
365
+ })),
366
+ indexes: t.indexes.map(i => ({
367
+ name: i.name,
368
+ columns: i.columns,
369
+ isUnique: i.unique,
370
+ type: i.type,
371
+ comment: i.comment,
372
+ })),
373
+ constraints: t.constraints || [],
374
+ isPartitioned: t.isPartitioned,
375
+ partitionType: t.partitionType,
376
+ partitionKey: t.partitionKey,
377
+ comment: t.comment,
378
+ })),
379
+ functions: localSnapshot.functions || [],
380
+ triggers: localSnapshot.triggers || [],
381
+ };
382
+ const remoteForCompare = {
383
+ extensions: dbSchema.extensions || [],
384
+ enums: filteredEnums || [],
385
+ domains: filteredDomains?.map(d => ({
386
+ name: d.name,
387
+ baseType: d.baseType,
388
+ isNotNull: d.isNotNull,
389
+ defaultValue: d.defaultValue,
390
+ checkExpression: d.checkExpression,
391
+ })) || [],
392
+ compositeTypes: filteredCompositeTypes || [],
393
+ sequences: [],
394
+ tables: filteredTables.map(t => ({
395
+ name: t.name,
396
+ schema: t.schema,
397
+ columns: t.columns.map(c => ({
398
+ name: c.name,
399
+ dataType: c.dataType,
400
+ isNullable: c.isNullable,
401
+ defaultValue: c.defaultValue,
402
+ isPrimaryKey: c.isPrimaryKey,
403
+ isUnique: c.isUnique,
404
+ comment: c.comment,
405
+ })),
406
+ indexes: t.indexes.map(i => ({
407
+ name: i.name,
408
+ columns: i.columns,
409
+ isUnique: i.isUnique,
410
+ type: i.type,
411
+ comment: i.comment,
412
+ })),
413
+ constraints: t.constraints || [],
414
+ isPartitioned: t.isPartitioned,
415
+ partitionType: t.partitionType,
416
+ partitionKey: t.partitionKey,
417
+ comment: t.comment,
418
+ })),
419
+ functions: filteredFunctions || [],
420
+ triggers: filteredTriggers || [],
421
+ };
422
+ const allChanges = compareSchemas(localForCompare, remoteForCompare);
423
+ const tablesAdded = allChanges.filter(c => c.type === 'CREATE' && c.objectType === 'TABLE').length;
424
+ const tablesRemoved = allChanges.filter(c => c.type === 'DROP' && c.objectType === 'TABLE').length;
425
+ const columnsChanged = allChanges.filter(c => c.objectType === 'COLUMN').length;
426
+ const indexesChanged = allChanges.filter(c => c.objectType === 'INDEX').length;
427
+ const otherChanges = allChanges.filter(c => c.objectType !== 'TABLE' && c.objectType !== 'COLUMN' && c.objectType !== 'INDEX').length;
346
428
  const conflicts = detectObjectConflicts(localSnapshot, currentSchema);
347
429
  if (conflicts.length > 0 && !force) {
348
430
  const mergeState = {
@@ -364,17 +446,26 @@ export async function pullCommand(context) {
364
446
  }
365
447
  fatal('Automatic merge failed; fix conflicts and then commit', `${colors.cyan('relq resolve --theirs <name>')} Take remote version\n${colors.cyan('relq resolve --all-theirs')} Take all remote\n${colors.cyan('relq pull --force')} Force overwrite local`);
366
448
  }
367
- if (added.length === 0 && removed.length === 0) {
449
+ if (allChanges.length === 0) {
368
450
  console.log('Already up to date with remote');
369
451
  console.log('');
370
452
  return;
371
453
  }
372
454
  console.log(`${colors.yellow('Remote has changes:')}`);
373
- if (added.length > 0) {
374
- console.log(` ${colors.green(`+${added.length}`)} tables added`);
455
+ if (tablesAdded > 0) {
456
+ console.log(` ${colors.green(`+${tablesAdded}`)} table(s) added`);
457
+ }
458
+ if (tablesRemoved > 0) {
459
+ console.log(` ${colors.red(`-${tablesRemoved}`)} table(s) removed`);
460
+ }
461
+ if (columnsChanged > 0) {
462
+ console.log(` ${colors.cyan(`~${columnsChanged}`)} column change(s)`);
463
+ }
464
+ if (indexesChanged > 0) {
465
+ console.log(` ${colors.cyan(`~${indexesChanged}`)} index change(s)`);
375
466
  }
376
- if (removed.length > 0) {
377
- console.log(` ${colors.red(`-${removed.length}`)} tables removed`);
467
+ if (otherChanges > 0) {
468
+ console.log(` ${colors.cyan(`~${otherChanges}`)} other change(s)`);
378
469
  }
379
470
  console.log('');
380
471
  const noAutoMerge = flags['no-auto-merge'] === true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relq",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "The Fully-Typed PostgreSQL ORM for TypeScript",
5
5
  "author": "Olajide Mathew O. <olajide.mathew@yuniq.solutions>",
6
6
  "license": "MIT",