Home / Function/ applyPgSnapshotsDiff() — drizzle-orm Function Reference

applyPgSnapshotsDiff() — drizzle-orm Function Reference

Architecture documentation for the applyPgSnapshotsDiff() function in snapshotsDiffer.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  c7a398db_43c9_7771_09b7_73bc09e703e8["applyPgSnapshotsDiff()"]
  582ba146_631b_7794_80a3_5b8044ba7cde["snapshotsDiffer.ts"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|defined in| 582ba146_631b_7794_80a3_5b8044ba7cde
  d532b567_3dc6_7be3_0c7e_e6f3a15eddff["introspectPostgres()"]
  d532b567_3dc6_7be3_0c7e_e6f3a15eddff -->|calls| c7a398db_43c9_7771_09b7_73bc09e703e8
  285d7baa_1c76_20e1_0c68_26eaff3a4a05["prepareAndMigratePg()"]
  285d7baa_1c76_20e1_0c68_26eaff3a4a05 -->|calls| c7a398db_43c9_7771_09b7_73bc09e703e8
  4e596a62_7d9b_59ea_a118_46bc45866220["prepareAndExportPg()"]
  4e596a62_7d9b_59ea_a118_46bc45866220 -->|calls| c7a398db_43c9_7771_09b7_73bc09e703e8
  64dd46c3_600a_69ef_c92f_904881477e81["preparePgPush()"]
  64dd46c3_600a_69ef_c92f_904881477e81 -->|calls| c7a398db_43c9_7771_09b7_73bc09e703e8
  560caeef_abdc_d66c_7c70_a78940262c2f["diffSchemasOrTables()"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|calls| 560caeef_abdc_d66c_7c70_a78940262c2f
  ea26ea35_7e38_edd5_dcf4_9309d7a255a4["schemasResolver()"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|calls| ea26ea35_7e38_edd5_dcf4_9309d7a255a4
  76b988d6_7533_c0ad_5fd9_3bef88fd1e57["copy()"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|calls| 76b988d6_7533_c0ad_5fd9_3bef88fd1e57
  e1545488_d3d6_a971_9398_55e765af330c["mapEntries()"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|calls| e1545488_d3d6_a971_9398_55e765af330c
  0db00779_feb2_cf90_31ff_ef0286d07da0["schemaChangeFor()"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|calls| 0db00779_feb2_cf90_31ff_ef0286d07da0
  2cb46387_de58_6ec4_428f_4bb77f77993b["enumsResolver()"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|calls| 2cb46387_de58_6ec4_428f_4bb77f77993b
  d4397b1a_b460_00f3_a94c_ee5c9fa31f9b["nameSchemaChangeFor()"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|calls| d4397b1a_b460_00f3_a94c_ee5c9fa31f9b
  920ff56d_9b78_d6a4_9c81_c1e6a3d1d992["mapValues()"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|calls| 920ff56d_9b78_d6a4_9c81_c1e6a3d1d992
  265d44ac_bb67_8fcd_3326_e0ebe5ffd4f7["sequencesResolver()"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|calls| 265d44ac_bb67_8fcd_3326_e0ebe5ffd4f7
  style c7a398db_43c9_7771_09b7_73bc09e703e8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/snapshotsDiffer.ts lines 559–2131

export const applyPgSnapshotsDiff = async (
	json1: PgSchemaSquashed,
	json2: PgSchemaSquashed,
	schemasResolver: (
		input: ResolverInput<Named>,
	) => Promise<ResolverOutput<Named>>,
	enumsResolver: (
		input: ResolverInput<Enum>,
	) => Promise<ResolverOutputWithMoved<Enum>>,
	sequencesResolver: (
		input: ResolverInput<Sequence>,
	) => Promise<ResolverOutputWithMoved<Sequence>>,
	policyResolver: (
		input: TablePolicyResolverInput<Policy>,
	) => Promise<TablePolicyResolverOutput<Policy>>,
	indPolicyResolver: (
		input: PolicyResolverInput<Policy>,
	) => Promise<PolicyResolverOutput<Policy>>,
	roleResolver: (
		input: RolesResolverInput<Role>,
	) => Promise<RolesResolverOutput<Role>>,
	tablesResolver: (
		input: ResolverInput<Table>,
	) => Promise<ResolverOutputWithMoved<Table>>,
	columnsResolver: (
		input: ColumnsResolverInput<Column>,
	) => Promise<ColumnsResolverOutput<Column>>,
	viewsResolver: (
		input: ResolverInput<View>,
	) => Promise<ResolverOutputWithMoved<View>>,
	prevFull: PgSchema,
	curFull: PgSchema,
	action?: 'push' | undefined,
): Promise<{
	statements: JsonStatement[];
	sqlStatements: string[];
	_meta:
		| {
			schemas: {};
			tables: {};
			columns: {};
		}
		| undefined;
}> => {
	const schemasDiff = diffSchemasOrTables(json1.schemas, json2.schemas);

	const {
		created: createdSchemas,
		deleted: deletedSchemas,
		renamed: renamedSchemas,
	} = await schemasResolver({
		created: schemasDiff.added.map((it) => ({ name: it })),
		deleted: schemasDiff.deleted.map((it) => ({ name: it })),
	});

	const schemasPatchedSnap1 = copy(json1);
	schemasPatchedSnap1.tables = mapEntries(
		schemasPatchedSnap1.tables,
		(_, it) => {
			const { key, schema } = schemaChangeFor(it, renamedSchemas);
			it.schema = schema;
			return [key, it];
		},
	);

	schemasPatchedSnap1.enums = mapEntries(schemasPatchedSnap1.enums, (_, it) => {
		const { key, schema } = schemaChangeFor(it, renamedSchemas);
		it.schema = schema;
		return [key, it];
	});

	const enumsDiff = diffSchemasOrTables(schemasPatchedSnap1.enums, json2.enums);

	const {
		created: createdEnums,
		deleted: deletedEnums,
		renamed: renamedEnums,
		moved: movedEnums,
	} = await enumsResolver({
		created: enumsDiff.added,
		deleted: enumsDiff.deleted,

Domain

Subdomains

Calls

Frequently Asked Questions

What does applyPgSnapshotsDiff() do?
applyPgSnapshotsDiff() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/snapshotsDiffer.ts.
Where is applyPgSnapshotsDiff() defined?
applyPgSnapshotsDiff() is defined in drizzle-kit/src/snapshotsDiffer.ts at line 559.
What does applyPgSnapshotsDiff() call?
applyPgSnapshotsDiff() calls 73 function(s): _prepareAddColumns, _prepareDropColumns, applyJsonDiff, columnChangeFor, columnsResolver, copy, diffColumns, diffIndPolicies, and 65 more.
What calls applyPgSnapshotsDiff()?
applyPgSnapshotsDiff() is called by 4 function(s): introspectPostgres, prepareAndExportPg, prepareAndMigratePg, preparePgPush.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free