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

applySingleStoreSnapshotsDiff() — drizzle-orm Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  d4992b27_bf78_8099_5134_750cef1c518c["applySingleStoreSnapshotsDiff()"]
  582ba146_631b_7794_80a3_5b8044ba7cde["snapshotsDiffer.ts"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|defined in| 582ba146_631b_7794_80a3_5b8044ba7cde
  7d387948_d073_7138_a827_23cf000dc9bc["introspectSingleStore()"]
  7d387948_d073_7138_a827_23cf000dc9bc -->|calls| d4992b27_bf78_8099_5134_750cef1c518c
  ca8ecd27_def2_e49f_f750_e3e6c8f46de5["prepareSingleStorePush()"]
  ca8ecd27_def2_e49f_f750_e3e6c8f46de5 -->|calls| d4992b27_bf78_8099_5134_750cef1c518c
  d3966aac_3570_4a25_bd4d_13770b298d13["prepareAndMigrateSingleStore()"]
  d3966aac_3570_4a25_bd4d_13770b298d13 -->|calls| d4992b27_bf78_8099_5134_750cef1c518c
  8c3dea15_1c5a_aaf1_d108_a7bbaf2815e6["prepareAndExportSinglestore()"]
  8c3dea15_1c5a_aaf1_d108_a7bbaf2815e6 -->|calls| d4992b27_bf78_8099_5134_750cef1c518c
  560caeef_abdc_d66c_7c70_a78940262c2f["diffSchemasOrTables()"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|calls| 560caeef_abdc_d66c_7c70_a78940262c2f
  2381bda1_f151_c72c_7494_6acc619c954d["tablesResolver()"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|calls| 2381bda1_f151_c72c_7494_6acc619c954d
  76b988d6_7533_c0ad_5fd9_3bef88fd1e57["copy()"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|calls| 76b988d6_7533_c0ad_5fd9_3bef88fd1e57
  e1545488_d3d6_a971_9398_55e765af330c["mapEntries()"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|calls| e1545488_d3d6_a971_9398_55e765af330c
  9338ffc1_dbdf_df1a_c471_9ced67e3244e["nameChangeFor()"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|calls| 9338ffc1_dbdf_df1a_c471_9ced67e3244e
  9e8ab4fa_ee1f_a20f_8211_19013f210efc["diffColumns()"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|calls| 9e8ab4fa_ee1f_a20f_8211_19013f210efc
  3b2eccf9_35d1_b2cc_b116_520f2f3c5d92["columnsResolver()"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|calls| 3b2eccf9_35d1_b2cc_b116_520f2f3c5d92
  baa46642_aaca_d735_ffb2_e540b4efa04b["mapKeys()"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|calls| baa46642_aaca_d735_ffb2_e540b4efa04b
  6ccba877_8f27_d835_30f0_d4f0b9b00400["columnChangeFor()"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|calls| 6ccba877_8f27_d835_30f0_d4f0b9b00400
  style d4992b27_bf78_8099_5134_750cef1c518c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/snapshotsDiffer.ts lines 2726–3237

export const applySingleStoreSnapshotsDiff = async (
	json1: SingleStoreSchemaSquashed,
	json2: SingleStoreSchemaSquashed,
	tablesResolver: (
		input: ResolverInput<Table>,
	) => Promise<ResolverOutputWithMoved<Table>>,
	columnsResolver: (
		input: ColumnsResolverInput<Column>,
	) => Promise<ColumnsResolverOutput<Column>>,
	/* viewsResolver: (
		input: ResolverInput<ViewSquashed & { schema: '' }>,
	) => Promise<ResolverOutputWithMoved<ViewSquashed>>, */
	prevFull: SingleStoreSchema,
	curFull: SingleStoreSchema,
	action?: 'push' | undefined,
): Promise<{
	statements: JsonStatement[];
	sqlStatements: string[];
	_meta:
		| {
			schemas: {};
			tables: {};
			columns: {};
		}
		| undefined;
}> => {
	// squash indexes and fks

	// squash uniqueIndexes and uniqueConstraint into constraints object
	// it should be done for singlestore only because it has no diffs for it

	// TODO: @AndriiSherman
	// Add an upgrade to v6 and move all snaphosts to this strcutre
	// After that we can generate singlestore in 1 object directly(same as sqlite)
	for (const tableName in json1.tables) {
		const table = json1.tables[tableName];
		for (const indexName in table.indexes) {
			const index = SingleStoreSquasher.unsquashIdx(table.indexes[indexName]);
			if (index.isUnique) {
				table.uniqueConstraints[indexName] = SingleStoreSquasher.squashUnique({
					name: index.name,
					columns: index.columns,
				});
				delete json1.tables[tableName].indexes[index.name];
			}
		}
	}

	for (const tableName in json2.tables) {
		const table = json2.tables[tableName];
		for (const indexName in table.indexes) {
			const index = SingleStoreSquasher.unsquashIdx(table.indexes[indexName]);
			if (index.isUnique) {
				table.uniqueConstraints[indexName] = SingleStoreSquasher.squashUnique({
					name: index.name,
					columns: index.columns,
				});
				delete json2.tables[tableName].indexes[index.name];
			}
		}
	}

	const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);

	const {
		created: createdTables,
		deleted: deletedTables,
		renamed: renamedTables, // renamed or moved
	} = await tablesResolver({
		created: tablesDiff.added,
		deleted: tablesDiff.deleted,
	});

	const tablesPatchedSnap1 = copy(json1);
	tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_, it) => {
		const { name } = nameChangeFor(it, renamedTables);
		it.name = name;
		return [name, it];
	});

	const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);

Domain

Subdomains

Frequently Asked Questions

What does applySingleStoreSnapshotsDiff() do?
applySingleStoreSnapshotsDiff() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/snapshotsDiffer.ts.
Where is applySingleStoreSnapshotsDiff() defined?
applySingleStoreSnapshotsDiff() is defined in drizzle-kit/src/snapshotsDiffer.ts at line 2726.
What does applySingleStoreSnapshotsDiff() call?
applySingleStoreSnapshotsDiff() calls 26 function(s): _prepareAddColumns, _prepareDropColumns, applyJsonDiff, columnChangeFor, columnsResolver, copy, diffColumns, diffSchemasOrTables, and 18 more.
What calls applySingleStoreSnapshotsDiff()?
applySingleStoreSnapshotsDiff() is called by 4 function(s): introspectSingleStore, prepareAndExportSinglestore, prepareAndMigrateSingleStore, prepareSingleStorePush.

Analyze Your Own Codebase

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

Try Supermodel Free