MCPcopy
hub / github.com/drizzle-team/drizzle-orm / applySqliteSnapshotsDiff

Function applySqliteSnapshotsDiff

drizzle-kit/src/snapshotsDiffer.ts:3239–3792  ·  view source on GitHub ↗
(
	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' | undefined,
)

Source from the content-addressed store, hash-verified

3237};
3238
3239export const applySqliteSnapshotsDiff = async (
3240 json1: SQLiteSchemaSquashed,
3241 json2: SQLiteSchemaSquashed,
3242 tablesResolver: (
3243 input: ResolverInput<Table>,
3244 ) => Promise<ResolverOutputWithMoved<Table>>,
3245 columnsResolver: (
3246 input: ColumnsResolverInput<Column>,
3247 ) => Promise<ColumnsResolverOutput<Column>>,
3248 viewsResolver: (
3249 input: ResolverInput<SqliteView & { schema: '' }>,
3250 ) => Promise<ResolverOutputWithMoved<SqliteView>>,
3251 prevFull: SQLiteSchema,
3252 curFull: SQLiteSchema,
3253 action?: 'push' | undefined,
3254): Promise<{
3255 statements: JsonStatement[];
3256 sqlStatements: string[];
3257 _meta:
3258 | {
3259 schemas: {};
3260 tables: {};
3261 columns: {};
3262 }
3263 | undefined;
3264}> => {
3265 const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
3266
3267 const {
3268 created: createdTables,
3269 deleted: deletedTables,
3270 renamed: renamedTables,
3271 } = await tablesResolver({
3272 created: tablesDiff.added,
3273 deleted: tablesDiff.deleted,
3274 });
3275
3276 const tablesPatchedSnap1 = copy(json1);
3277 tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_, it) => {
3278 const { name } = nameChangeFor(it, renamedTables);
3279 it.name = name;
3280 return [name, it];
3281 });
3282
3283 const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);
3284
3285 const columnRenames = [] as {
3286 table: string;
3287 renames: { from: Column; to: Column }[];
3288 }[];
3289
3290 const columnCreates = [] as {
3291 table: string;
3292 columns: Column[];
3293 }[];
3294
3295 const columnDeletes = [] as {
3296 table: string;

Callers 10

introspectSqliteFunction · 0.90
prepareAndMigrateSqliteFunction · 0.90
prepareAndExportSqliteFunction · 0.90
prepareSQLitePushFunction · 0.90
applySqliteDiffsFunction · 0.90
diffTestSchemasSqliteFunction · 0.90
introspectSQLiteToFileFunction · 0.90
generateSQLiteMigrationFunction · 0.85
pushSQLiteSchemaFunction · 0.85

Calls 15

diffSchemasOrTablesFunction · 0.90
copyFunction · 0.90
mapEntriesFunction · 0.90
diffColumnsFunction · 0.90
mapKeysFunction · 0.90
applyJsonDiffFunction · 0.90
prepareSQLiteCreateTableFunction · 0.90
prepareCreateIndexesJsonFunction · 0.90
prepareDropTableJsonFunction · 0.90
prepareRenameTableJsonFunction · 0.90
prepareRenameColumnsFunction · 0.90
_prepareDropColumnsFunction · 0.90

Tested by

no test coverage detected