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

Function diffTestSchemasPush

drizzle-kit/tests/schemaDiffer.ts:940–1128  ·  view source on GitHub ↗
(
	client: PGlite,
	left: PostgresSchema,
	right: PostgresSchema,
	renamesArr: string[],
	cli: boolean = false,
	schemas: string[] = ['public'],
	casing?: CasingType | undefined,
	entities?: Entities,
	sqlStatementsToRun: {
		before?: string[];
		after?: string[];
		runApply?: boolean;
	} = {
		before: [],
		after: [],
		runApply: true,
	},
)

Source from the content-addressed store, hash-verified

938};
939
940export const diffTestSchemasPush = async (
941 client: PGlite,
942 left: PostgresSchema,
943 right: PostgresSchema,
944 renamesArr: string[],
945 cli: boolean = false,
946 schemas: string[] = ['public'],
947 casing?: CasingType | undefined,
948 entities?: Entities,
949 sqlStatementsToRun: {
950 before?: string[];
951 after?: string[];
952 runApply?: boolean;
953 } = {
954 before: [],
955 after: [],
956 runApply: true,
957 },
958) => {
959 const shouldRunApply = sqlStatementsToRun.runApply === undefined
960 ? true
961 : sqlStatementsToRun.runApply;
962
963 for (const st of sqlStatementsToRun.before ?? []) {
964 await client.query(st);
965 }
966
967 if (shouldRunApply) {
968 const res = await applyPgDiffs(left, casing);
969 for (const st of res.sqlStatements) {
970 await client.query(st);
971 }
972 }
973
974 for (const st of sqlStatementsToRun.after ?? []) {
975 await client.query(st);
976 }
977
978 const materializedViewsForRefresh = Object.values(left).filter((it) =>
979 isPgMaterializedView(it)
980 ) as PgMaterializedView[];
981
982 // refresh all mat views
983 for (const view of materializedViewsForRefresh) {
984 const viewConf = getMaterializedViewConfig(view);
985 if (viewConf.isExisting) continue;
986
987 await client.exec(
988 `REFRESH MATERIALIZED VIEW "${viewConf.schema ?? 'public'}"."${viewConf.name}"${
989 viewConf.withNoData ? ' WITH NO DATA;' : ';'
990 }`,
991 );
992 }
993
994 // do introspect into PgSchemaInternal
995 const introspectedSchema = await fromDatabase(
996 {
997 query: async (query: string, values?: any[] | undefined) => {

Callers 15

allTypesFunction · 0.90
addBasicIndexesFunction · 0.90
addGeneratedColumnFunction · 0.90
addGeneratedToColumnFunction · 0.90
dropGeneratedConstraintFunction · 0.90
alterGeneratedConstraintFunction · 0.90
addBasicSequencesFunction · 0.90
changeIndexFieldsFunction · 0.90
dropIndexFunction · 0.90
indexesToBeNotTriggeredFunction · 0.90
indexesTestCase1Function · 0.90

Calls 15

isPgMaterializedViewFunction · 0.90
fromDatabaseFunction · 0.90
isFunction · 0.90
isPgEnumFunction · 0.90
isPgSequenceFunction · 0.90
isPgViewFunction · 0.90
generatePgSnapshotFunction · 0.90
squashPgSchemeFunction · 0.90
applyPgSnapshotsDiffFunction · 0.90
pgSuggestionsFunction · 0.90
applyPgDiffsFunction · 0.85

Tested by 15

allTypesFunction · 0.72
addBasicIndexesFunction · 0.72
addGeneratedColumnFunction · 0.72
addGeneratedToColumnFunction · 0.72
dropGeneratedConstraintFunction · 0.72
alterGeneratedConstraintFunction · 0.72
addBasicSequencesFunction · 0.72
changeIndexFieldsFunction · 0.72
dropIndexFunction · 0.72
indexesToBeNotTriggeredFunction · 0.72
indexesTestCase1Function · 0.72