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

Function testViewsResolverMySql

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

Source from the content-addressed store, hash-verified

718};
719
720export const testViewsResolverMySql = (renames: Set<string>) =>
721async (
722 input: ResolverInput<ViewSquashed & { schema: '' }>,
723): Promise<ResolverOutputWithMoved<ViewSquashed>> => {
724 try {
725 if (
726 input.created.length === 0
727 || input.deleted.length === 0
728 || renames.size === 0
729 ) {
730 return {
731 created: input.created,
732 moved: [],
733 renamed: [],
734 deleted: input.deleted,
735 };
736 }
737
738 let createdViews = [...input.created];
739 let deletedViews = [...input.deleted];
740
741 const result: {
742 created: ViewSquashed[];
743 moved: { name: string; schemaFrom: string; schemaTo: string }[];
744 renamed: { from: ViewSquashed; to: ViewSquashed }[];
745 deleted: ViewSquashed[];
746 } = { created: [], renamed: [], deleted: [], moved: [] };
747
748 for (let rename of renames) {
749 const [from, to] = rename.split('->');
750
751 const idxFrom = deletedViews.findIndex((it) => {
752 return `${it.schema || 'public'}.${it.name}` === from;
753 });
754
755 if (idxFrom >= 0) {
756 const idxTo = createdViews.findIndex((it) => {
757 return `${it.schema || 'public'}.${it.name}` === to;
758 });
759
760 const viewFrom = deletedViews[idxFrom];
761 const viewTo = createdViews[idxFrom];
762
763 if (viewFrom.schema !== viewTo.schema) {
764 result.moved.push({
765 name: viewFrom.name,
766 schemaFrom: viewFrom.schema,
767 schemaTo: viewTo.schema,
768 });
769 }
770
771 if (viewFrom.name !== viewTo.name) {
772 result.renamed.push({
773 from: deletedViews[idxFrom],
774 to: createdViews[idxTo],
775 });
776 }
777

Callers 4

diffTestSchemasPushMysqlFunction · 0.85
applyMySqlDiffsFunction · 0.85
diffTestSchemasMysqlFunction · 0.85
introspectMySQLToFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected