Skip to content

Commit

Permalink
Fix migration fetching to return migrations in the correct order
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclarke committed Aug 15, 2024
1 parent 9902ff4 commit e46ce03
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions shared/common/branchGraph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,29 @@ export const BranchGraph = observer(function BranchGraph({
findGraphItemBranch(graphItems[0])
);
const result = await conn.query(
`select (
select schema::Migration
filter .name in array_unpack(<array<str>>$names)
).script`,
`select schema::Migration {
name,
script
}
filter .name in array_unpack(<array<str>>$names)`,
{names: graphItems.map((item) => item.name)}
);
const scripts = result.result;
if (scripts == null || scripts.length != graphItems.length) {
const migrations = new Map(
result.result?.map((m) => [m.name, m.script])
);

const missingMigrations = graphItems
.map((item) => item.name)
.filter((name) => !migrations.has(name));

if (missingMigrations.length) {
throw new Error(
`Migrations not found for ${graphItems
.map((item) => item.name)
.join(", ")}`
`Migrations not found for ${missingMigrations.join(", ")}`
);
}
return scripts as string[];
return graphItems.map((item) =>
migrations.get(item.name)
) as string[];
};

return (
Expand Down

0 comments on commit e46ce03

Please sign in to comment.