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

Function applyLibSQLSnapshotsDiff

drizzle-kit/src/snapshotsDiffer.ts:3794–4328  ·  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',
)

Source from the content-addressed store, hash-verified

3792};
3793
3794export const applyLibSQLSnapshotsDiff = async (
3795 json1: SQLiteSchemaSquashed,
3796 json2: SQLiteSchemaSquashed,
3797 tablesResolver: (
3798 input: ResolverInput<Table>,
3799 ) => Promise<ResolverOutputWithMoved<Table>>,
3800 columnsResolver: (
3801 input: ColumnsResolverInput<Column>,
3802 ) => Promise<ColumnsResolverOutput<Column>>,
3803 viewsResolver: (
3804 input: ResolverInput<SqliteView & { schema: '' }>,
3805 ) => Promise<ResolverOutputWithMoved<SqliteView>>,
3806 prevFull: SQLiteSchema,
3807 curFull: SQLiteSchema,
3808 action?: 'push',
3809): Promise<{
3810 statements: JsonStatement[];
3811 sqlStatements: string[];
3812 _meta:
3813 | {
3814 schemas: {};
3815 tables: {};
3816 columns: {};
3817 }
3818 | undefined;
3819}> => {
3820 const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
3821 const {
3822 created: createdTables,
3823 deleted: deletedTables,
3824 renamed: renamedTables,
3825 } = await tablesResolver({
3826 created: tablesDiff.added,
3827 deleted: tablesDiff.deleted,
3828 });
3829
3830 const tablesPatchedSnap1 = copy(json1);
3831 tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_, it) => {
3832 const { name } = nameChangeFor(it, renamedTables);
3833 it.name = name;
3834 return [name, it];
3835 });
3836
3837 const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);
3838
3839 const columnRenames = [] as {
3840 table: string;
3841 renames: { from: Column; to: Column }[];
3842 }[];
3843
3844 const columnCreates = [] as {
3845 table: string;
3846 columns: Column[];
3847 }[];
3848
3849 const columnDeletes = [] as {
3850 table: string;
3851 columns: Column[];

Callers 8

introspectLibSQLFunction · 0.90
prepareAndMigrateLibSQLFunction · 0.90
prepareAndExportLibSQLFunction · 0.90
prepareLibSQLPushFunction · 0.90
applyLibSQLDiffsFunction · 0.90
diffTestSchemasLibSQLFunction · 0.90
introspectLibSQLToFileFunction · 0.90

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