MCPcopy
hub / github.com/drizzle-team/drizzle-orm / findAlternationsInTable

Function findAlternationsInTable

drizzle-kit/src/jsonDiffer.js:413–572  ·  view source on GitHub ↗
(table)

Source from the content-addressed store, hash-verified

411}
412
413const findAlternationsInTable = (table) => {
414 // map each table to have altered, deleted or renamed columns
415
416 // in case no columns were altered, but indexes were
417 const columns = table.columns ?? {};
418
419 const altered = Object.keys(columns)
420 .filter((it) => !(it.includes('__deleted') || it.includes('__added')))
421 .map((it) => {
422 return { name: it, ...columns[it] };
423 });
424
425 const deletedIndexes = Object.fromEntries(
426 Object.entries(table.indexes__deleted || {})
427 .concat(
428 Object.entries(table.indexes || {}).filter((it) => it[0].includes('__deleted')),
429 )
430 .map((entry) => [entry[0].replace('__deleted', ''), entry[1]]),
431 );
432
433 const addedIndexes = Object.fromEntries(
434 Object.entries(table.indexes__added || {})
435 .concat(
436 Object.entries(table.indexes || {}).filter((it) => it[0].includes('__added')),
437 )
438 .map((entry) => [entry[0].replace('__added', ''), entry[1]]),
439 );
440
441 const alteredIndexes = Object.fromEntries(
442 Object.entries(table.indexes || {}).filter((it) => {
443 return !it[0].endsWith('__deleted') && !it[0].endsWith('__added');
444 }),
445 );
446
447 const deletedPolicies = Object.fromEntries(
448 Object.entries(table.policies__deleted || {})
449 .concat(
450 Object.entries(table.policies || {}).filter((it) => it[0].includes('__deleted')),
451 )
452 .map((entry) => [entry[0].replace('__deleted', ''), entry[1]]),
453 );
454
455 const addedPolicies = Object.fromEntries(
456 Object.entries(table.policies__added || {})
457 .concat(
458 Object.entries(table.policies || {}).filter((it) => it[0].includes('__added')),
459 )
460 .map((entry) => [entry[0].replace('__added', ''), entry[1]]),
461 );
462
463 const alteredPolicies = Object.fromEntries(
464 Object.entries(table.policies || {}).filter((it) => {
465 return !it[0].endsWith('__deleted') && !it[0].endsWith('__added');
466 }),
467 );
468
469 const deletedForeignKeys = Object.fromEntries(
470 Object.entries(table.foreignKeys__deleted || {})

Callers 2

diffForRenamedTableFunction · 0.85
applyJsonDiffFunction · 0.85

Calls 1

alternationsInColumnFunction · 0.85

Tested by

no test coverage detected