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

Function squashMysqlScheme

drizzle-kit/src/serializer/mysqlSchema.ts:338–399  ·  view source on GitHub ↗
(json: MySqlSchema)

Source from the content-addressed store, hash-verified

336};
337
338export const squashMysqlScheme = (json: MySqlSchema): MySqlSchemaSquashed => {
339 const mappedTables = Object.fromEntries(
340 Object.entries(json.tables).map((it) => {
341 const squashedIndexes = mapValues(it[1].indexes, (index) => {
342 return MySqlSquasher.squashIdx(index);
343 });
344
345 const squashedFKs = mapValues(it[1].foreignKeys, (fk) => {
346 return MySqlSquasher.squashFK(fk);
347 });
348
349 const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
350 return MySqlSquasher.squashPK(pk);
351 });
352
353 const squashedUniqueConstraints = mapValues(
354 it[1].uniqueConstraints,
355 (unq) => {
356 return MySqlSquasher.squashUnique(unq);
357 },
358 );
359
360 const squashedCheckConstraints = mapValues(it[1].checkConstraint, (check) => {
361 return MySqlSquasher.squashCheck(check);
362 });
363
364 return [
365 it[0],
366 {
367 name: it[1].name,
368 columns: it[1].columns,
369 indexes: squashedIndexes,
370 foreignKeys: squashedFKs,
371 compositePrimaryKeys: squashedPKs,
372 uniqueConstraints: squashedUniqueConstraints,
373 checkConstraints: squashedCheckConstraints,
374 },
375 ];
376 }),
377 );
378
379 const mappedViews = Object.fromEntries(
380 Object.entries(json.views).map(([key, value]) => {
381 const meta = MySqlSquasher.squashView(value);
382
383 return [key, {
384 name: value.name,
385 isExisting: value.isExisting,
386 columns: value.columns,
387 definition: value.definition,
388 meta,
389 }];
390 }),
391 );
392
393 return {
394 version: '5',
395 dialect: json.dialect,

Callers 10

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

Calls 1

mapValuesFunction · 0.90

Tested by

no test coverage detected