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

Function testIndPolicyResolver

drizzle-kit/tests/schemaDiffer.ts:528–584  ·  view source on GitHub ↗
(renames: Set<string>)

Source from the content-addressed store, hash-verified

526};
527
528export const testIndPolicyResolver = (renames: Set<string>) =>
529async (
530 input: PolicyResolverInput<Policy>,
531): Promise<PolicyResolverOutput<Policy>> => {
532 try {
533 if (
534 input.created.length === 0
535 || input.deleted.length === 0
536 || renames.size === 0
537 ) {
538 return {
539 created: input.created,
540 renamed: [],
541 deleted: input.deleted,
542 };
543 }
544
545 let createdPolicies = [...input.created];
546 let deletedPolicies = [...input.deleted];
547
548 const renamed: { from: Policy; to: Policy }[] = [];
549
550 for (let rename of renames) {
551 const [from, to] = rename.split('->');
552
553 const idxFrom = deletedPolicies.findIndex((it) => {
554 return `${it.on}.${it.name}` === from;
555 });
556
557 if (idxFrom >= 0) {
558 const idxTo = createdPolicies.findIndex((it) => {
559 return `${it.on}.${it.name}` === to;
560 });
561
562 renamed.push({
563 from: deletedPolicies[idxFrom],
564 to: createdPolicies[idxTo],
565 });
566
567 delete createdPolicies[idxTo];
568 delete deletedPolicies[idxFrom];
569
570 createdPolicies = createdPolicies.filter(Boolean);
571 deletedPolicies = deletedPolicies.filter(Boolean);
572 }
573 }
574
575 return {
576 created: createdPolicies,
577 deleted: deletedPolicies,
578 renamed,
579 };
580 } catch (e) {
581 console.error(e);
582 throw e;
583 }
584};
585

Callers 4

diffTestSchemasPushFunction · 0.85
applyPgDiffsFunction · 0.85
diffTestSchemasFunction · 0.85
introspectPgToFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected