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

Function applyMysqlSnapshotsDiff

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

Source from the content-addressed store, hash-verified

2131};
2132
2133export const applyMysqlSnapshotsDiff = async (
2134 json1: MySqlSchemaSquashed,
2135 json2: MySqlSchemaSquashed,
2136 tablesResolver: (
2137 input: ResolverInput<Table>,
2138 ) => Promise<ResolverOutputWithMoved<Table>>,
2139 columnsResolver: (
2140 input: ColumnsResolverInput<Column>,
2141 ) => Promise<ColumnsResolverOutput<Column>>,
2142 viewsResolver: (
2143 input: ResolverInput<ViewSquashed & { schema: '' }>,
2144 ) => Promise<ResolverOutputWithMoved<ViewSquashed>>,
2145 prevFull: MySqlSchema,
2146 curFull: MySqlSchema,
2147 action?: 'push' | undefined,
2148): Promise<{
2149 statements: JsonStatement[];
2150 sqlStatements: string[];
2151 _meta:
2152 | {
2153 schemas: {};
2154 tables: {};
2155 columns: {};
2156 }
2157 | undefined;
2158}> => {
2159 // squash indexes and fks
2160
2161 // squash uniqueIndexes and uniqueConstraint into constraints object
2162 // it should be done for mysql only because it has no diffs for it
2163
2164 // TODO: @AndriiSherman
2165 // Add an upgrade to v6 and move all snaphosts to this strcutre
2166 // After that we can generate mysql in 1 object directly(same as sqlite)
2167 for (const tableName in json1.tables) {
2168 const table = json1.tables[tableName];
2169 for (const indexName in table.indexes) {
2170 const index = MySqlSquasher.unsquashIdx(table.indexes[indexName]);
2171 if (index.isUnique) {
2172 table.uniqueConstraints[indexName] = MySqlSquasher.squashUnique({
2173 name: index.name,
2174 columns: index.columns,
2175 });
2176 delete json1.tables[tableName].indexes[index.name];
2177 }
2178 }
2179 }
2180
2181 for (const tableName in json2.tables) {
2182 const table = json2.tables[tableName];
2183 for (const indexName in table.indexes) {
2184 const index = MySqlSquasher.unsquashIdx(table.indexes[indexName]);
2185 if (index.isUnique) {
2186 table.uniqueConstraints[indexName] = MySqlSquasher.squashUnique({
2187 name: index.name,
2188 columns: index.columns,
2189 });
2190 delete json2.tables[tableName].indexes[index.name];

Callers 10

introspectMysqlFunction · 0.90
prepareMySQLPushFunction · 0.90
prepareAndMigrateMysqlFunction · 0.90
prepareAndExportMysqlFunction · 0.90
diffTestSchemasPushMysqlFunction · 0.90
applyMySqlDiffsFunction · 0.90
diffTestSchemasMysqlFunction · 0.90
introspectMySQLToFileFunction · 0.90
generateMySQLMigrationFunction · 0.85
pushMySQLSchemaFunction · 0.85

Calls 15

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

Tested by

no test coverage detected