applyMysqlSnapshotsDiff() — drizzle-orm Function Reference
Architecture documentation for the applyMysqlSnapshotsDiff() function in snapshotsDiffer.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD a5972ffc_ff1b_9523_2495_5373af710e65["applyMysqlSnapshotsDiff()"] 582ba146_631b_7794_80a3_5b8044ba7cde["snapshotsDiffer.ts"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|defined in| 582ba146_631b_7794_80a3_5b8044ba7cde 50854fb8_da44_d90e_33cd_3524dcf8268c["introspectMysql()"] 50854fb8_da44_d90e_33cd_3524dcf8268c -->|calls| a5972ffc_ff1b_9523_2495_5373af710e65 f33a49b1_2979_711d_4a14_81aa99a6f2a0["prepareMySQLPush()"] f33a49b1_2979_711d_4a14_81aa99a6f2a0 -->|calls| a5972ffc_ff1b_9523_2495_5373af710e65 41b84052_7d33_8f63_3c95_ec57735ef60e["prepareAndMigrateMysql()"] 41b84052_7d33_8f63_3c95_ec57735ef60e -->|calls| a5972ffc_ff1b_9523_2495_5373af710e65 eaa78cbd_5a13_740d_6e64_0c3173007ebb["prepareAndExportMysql()"] eaa78cbd_5a13_740d_6e64_0c3173007ebb -->|calls| a5972ffc_ff1b_9523_2495_5373af710e65 560caeef_abdc_d66c_7c70_a78940262c2f["diffSchemasOrTables()"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| 560caeef_abdc_d66c_7c70_a78940262c2f 2381bda1_f151_c72c_7494_6acc619c954d["tablesResolver()"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| 2381bda1_f151_c72c_7494_6acc619c954d 76b988d6_7533_c0ad_5fd9_3bef88fd1e57["copy()"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| 76b988d6_7533_c0ad_5fd9_3bef88fd1e57 e1545488_d3d6_a971_9398_55e765af330c["mapEntries()"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| e1545488_d3d6_a971_9398_55e765af330c 9338ffc1_dbdf_df1a_c471_9ced67e3244e["nameChangeFor()"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| 9338ffc1_dbdf_df1a_c471_9ced67e3244e 9e8ab4fa_ee1f_a20f_8211_19013f210efc["diffColumns()"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| 9e8ab4fa_ee1f_a20f_8211_19013f210efc 3b2eccf9_35d1_b2cc_b116_520f2f3c5d92["columnsResolver()"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| 3b2eccf9_35d1_b2cc_b116_520f2f3c5d92 baa46642_aaca_d735_ffb2_e540b4efa04b["mapKeys()"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| baa46642_aaca_d735_ffb2_e540b4efa04b 6ccba877_8f27_d835_30f0_d4f0b9b00400["columnChangeFor()"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| 6ccba877_8f27_d835_30f0_d4f0b9b00400 style a5972ffc_ff1b_9523_2495_5373af710e65 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/snapshotsDiffer.ts lines 2133–2724
export const applyMysqlSnapshotsDiff = async (
json1: MySqlSchemaSquashed,
json2: MySqlSchemaSquashed,
tablesResolver: (
input: ResolverInput<Table>,
) => Promise<ResolverOutputWithMoved<Table>>,
columnsResolver: (
input: ColumnsResolverInput<Column>,
) => Promise<ColumnsResolverOutput<Column>>,
viewsResolver: (
input: ResolverInput<ViewSquashed & { schema: '' }>,
) => Promise<ResolverOutputWithMoved<ViewSquashed>>,
prevFull: MySqlSchema,
curFull: MySqlSchema,
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 mysql 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 mysql 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 = MySqlSquasher.unsquashIdx(table.indexes[indexName]);
if (index.isUnique) {
table.uniqueConstraints[indexName] = MySqlSquasher.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 = MySqlSquasher.unsquashIdx(table.indexes[indexName]);
if (index.isUnique) {
table.uniqueConstraints[indexName] = MySqlSquasher.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
Defined In
Calls
- _prepareAddColumns()
- _prepareDropColumns()
- applyJsonDiff()
- columnChangeFor()
- columnsResolver()
- copy()
- diffColumns()
- diffSchemasOrTables()
- fromJson()
- mapEntries()
- mapKeys()
- nameChangeFor()
- prepareAddCheckConstraint()
- prepareAddCompositePrimaryKeyMySql()
- prepareAlterColumnsMysql()
- prepareAlterCompositePrimaryKeyMySql()
- prepareAlterReferencesJson()
- prepareCreateIndexesJson()
- prepareCreateReferencesJson()
- prepareDeleteCheckConstraint()
- prepareDeleteCompositePrimaryKeyMySql()
- prepareDropIndexesJson()
- prepareDropReferencesJson()
- prepareDropTableJson()
- prepareMigrationMeta()
- prepareMySqlAlterView()
- prepareMySqlCreateTableJson()
- prepareRenameColumns()
- prepareRenameTableJson()
- prepareRenameViewJson()
- tablesResolver()
- viewsResolver()
Source
Frequently Asked Questions
What does applyMysqlSnapshotsDiff() do?
applyMysqlSnapshotsDiff() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/snapshotsDiffer.ts.
Where is applyMysqlSnapshotsDiff() defined?
applyMysqlSnapshotsDiff() is defined in drizzle-kit/src/snapshotsDiffer.ts at line 2133.
What does applyMysqlSnapshotsDiff() call?
applyMysqlSnapshotsDiff() calls 32 function(s): _prepareAddColumns, _prepareDropColumns, applyJsonDiff, columnChangeFor, columnsResolver, copy, diffColumns, diffSchemasOrTables, and 24 more.
What calls applyMysqlSnapshotsDiff()?
applyMysqlSnapshotsDiff() is called by 4 function(s): introspectMysql, prepareAndExportMysql, prepareAndMigrateMysql, prepareMySQLPush.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free