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

applyLibSQLSnapshotsDiff() — drizzle-orm Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  55569cde_7638_9cfc_9dcd_34636d975ec3["applyLibSQLSnapshotsDiff()"]
  582ba146_631b_7794_80a3_5b8044ba7cde["snapshotsDiffer.ts"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|defined in| 582ba146_631b_7794_80a3_5b8044ba7cde
  49e2c573_17ba_89fe_104a_c5be22a2db77["introspectLibSQL()"]
  49e2c573_17ba_89fe_104a_c5be22a2db77 -->|calls| 55569cde_7638_9cfc_9dcd_34636d975ec3
  fb79a54b_99a5_2063_0a0c_a9cc728865a9["prepareAndMigrateLibSQL()"]
  fb79a54b_99a5_2063_0a0c_a9cc728865a9 -->|calls| 55569cde_7638_9cfc_9dcd_34636d975ec3
  86d84611_0fad_b786_2a9e_f7b234a52b6c["prepareAndExportLibSQL()"]
  86d84611_0fad_b786_2a9e_f7b234a52b6c -->|calls| 55569cde_7638_9cfc_9dcd_34636d975ec3
  bc8e732d_406a_2bba_c78e_33845d67094a["prepareLibSQLPush()"]
  bc8e732d_406a_2bba_c78e_33845d67094a -->|calls| 55569cde_7638_9cfc_9dcd_34636d975ec3
  560caeef_abdc_d66c_7c70_a78940262c2f["diffSchemasOrTables()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| 560caeef_abdc_d66c_7c70_a78940262c2f
  2381bda1_f151_c72c_7494_6acc619c954d["tablesResolver()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| 2381bda1_f151_c72c_7494_6acc619c954d
  76b988d6_7533_c0ad_5fd9_3bef88fd1e57["copy()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| 76b988d6_7533_c0ad_5fd9_3bef88fd1e57
  e1545488_d3d6_a971_9398_55e765af330c["mapEntries()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| e1545488_d3d6_a971_9398_55e765af330c
  9338ffc1_dbdf_df1a_c471_9ced67e3244e["nameChangeFor()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| 9338ffc1_dbdf_df1a_c471_9ced67e3244e
  9e8ab4fa_ee1f_a20f_8211_19013f210efc["diffColumns()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| 9e8ab4fa_ee1f_a20f_8211_19013f210efc
  3b2eccf9_35d1_b2cc_b116_520f2f3c5d92["columnsResolver()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| 3b2eccf9_35d1_b2cc_b116_520f2f3c5d92
  baa46642_aaca_d735_ffb2_e540b4efa04b["mapKeys()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| baa46642_aaca_d735_ffb2_e540b4efa04b
  6ccba877_8f27_d835_30f0_d4f0b9b00400["columnChangeFor()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| 6ccba877_8f27_d835_30f0_d4f0b9b00400
  style 55569cde_7638_9cfc_9dcd_34636d975ec3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/snapshotsDiffer.ts lines 3794–4328

export const applyLibSQLSnapshotsDiff = async (
	json1: SQLiteSchemaSquashed,
	json2: SQLiteSchemaSquashed,
	tablesResolver: (
		input: ResolverInput<Table>,
	) => Promise<ResolverOutputWithMoved<Table>>,
	columnsResolver: (
		input: ColumnsResolverInput<Column>,
	) => Promise<ColumnsResolverOutput<Column>>,
	viewsResolver: (
		input: ResolverInput<SqliteView & { schema: '' }>,
	) => Promise<ResolverOutputWithMoved<SqliteView>>,
	prevFull: SQLiteSchema,
	curFull: SQLiteSchema,
	action?: 'push',
): Promise<{
	statements: JsonStatement[];
	sqlStatements: string[];
	_meta:
		| {
			schemas: {};
			tables: {};
			columns: {};
		}
		| undefined;
}> => {
	const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
	const {
		created: createdTables,
		deleted: deletedTables,
		renamed: renamedTables,
	} = 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);

	const columnRenames = [] as {
		table: string;
		renames: { from: Column; to: Column }[];
	}[];

	const columnCreates = [] as {
		table: string;
		columns: Column[];
	}[];

	const columnDeletes = [] as {
		table: string;
		columns: Column[];
	}[];

	for (let entry of Object.values(res)) {
		const { renamed, created, deleted } = await columnsResolver({
			tableName: entry.name,
			schema: entry.schema,
			deleted: entry.columns.deleted,
			created: entry.columns.added,
		});

		if (created.length > 0) {
			columnCreates.push({
				table: entry.name,
				columns: created,
			});
		}

		if (deleted.length > 0) {
			columnDeletes.push({
				table: entry.name,
				columns: deleted,
			});
		}

Domain

Subdomains

Frequently Asked Questions

What does applyLibSQLSnapshotsDiff() do?
applyLibSQLSnapshotsDiff() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/snapshotsDiffer.ts.
Where is applyLibSQLSnapshotsDiff() defined?
applyLibSQLSnapshotsDiff() is defined in drizzle-kit/src/snapshotsDiffer.ts at line 3794.
What does applyLibSQLSnapshotsDiff() call?
applyLibSQLSnapshotsDiff() calls 31 function(s): _prepareDropColumns, _prepareSqliteAddColumns, applyJsonDiff, columnChangeFor, columnsResolver, copy, diffColumns, diffSchemasOrTables, and 23 more.
What calls applyLibSQLSnapshotsDiff()?
applyLibSQLSnapshotsDiff() is called by 4 function(s): introspectLibSQL, prepareAndExportLibSQL, prepareAndMigrateLibSQL, prepareLibSQLPush.

Analyze Your Own Codebase

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

Try Supermodel Free