| 938 | }; |
| 939 | |
| 940 | export 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) => { |