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

Function testTablesResolver

drizzle-kit/tests/schemaDiffer.ts:324–398  ·  view source on GitHub ↗
(renames: Set<string>)

Source from the content-addressed store, hash-verified

322};
323
324export const testTablesResolver = (renames: Set<string>) =>
325async (
326 input: ResolverInput<Table>,
327): Promise<ResolverOutputWithMoved<Table>> => {
328 try {
329 if (
330 input.created.length === 0
331 || input.deleted.length === 0
332 || renames.size === 0
333 ) {
334 return {
335 created: input.created,
336 moved: [],
337 renamed: [],
338 deleted: input.deleted,
339 };
340 }
341
342 let createdTables = [...input.created];
343 let deletedTables = [...input.deleted];
344
345 const result: {
346 created: Table[];
347 moved: { name: string; schemaFrom: string; schemaTo: string }[];
348 renamed: { from: Table; to: Table }[];
349 deleted: Table[];
350 } = { created: [], renamed: [], deleted: [], moved: [] };
351
352 for (let rename of renames) {
353 const [from, to] = rename.split('->');
354
355 const idxFrom = deletedTables.findIndex((it) => {
356 return `${it.schema || 'public'}.${it.name}` === from;
357 });
358
359 if (idxFrom >= 0) {
360 const idxTo = createdTables.findIndex((it) => {
361 return `${it.schema || 'public'}.${it.name}` === to;
362 });
363
364 const tableFrom = deletedTables[idxFrom];
365 const tableTo = createdTables[idxFrom];
366
367 if (tableFrom.schema !== tableTo.schema) {
368 result.moved.push({
369 name: tableFrom.name,
370 schemaFrom: tableFrom.schema,
371 schemaTo: tableTo.schema,
372 });
373 }
374
375 if (tableFrom.name !== tableTo.name) {
376 result.renamed.push({
377 from: deletedTables[idxFrom],
378 to: createdTables[idxTo],
379 });
380 }
381

Callers 15

diffTestSchemasPushFunction · 0.85
applyPgDiffsFunction · 0.85
diffTestSchemasFunction · 0.85
diffTestSchemasPushMysqlFunction · 0.85
applyMySqlDiffsFunction · 0.85
diffTestSchemasMysqlFunction · 0.85
applySingleStoreDiffsFunction · 0.85
applySqliteDiffsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected