Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
feat: keep the table order of the table whitelist (#73)
Browse files Browse the repository at this point in the history
* keep the table order of the table whitelist

When providing a table whitelist the order of that whitelist should be kept when dumping the tables.

This helps if dumping the database without table locks and having tables with foreign key references into other tables. By carefully defining the order of tables you can still achieve a consistent dump without violating the referential integrity by first dumping the table containing the foreign key, followed by the table which is the target of the reference.

* replace `type cast` by `type predicate and minor code cleanup based on review
  • Loading branch information
Kosta-Github authored and bradzacher committed Jul 19, 2019
1 parent 06b7cb8 commit 98f0c9d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/getTables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ async function getTables(
);
} else {
// only include the tables from the options that actually exist in the db
tables = tables.filter(
t => restrictedTables.indexOf(t.name) !== -1,
);
// keeping the order of the passed-in whitelist and filtering out non-existing tables
tables = restrictedTables
.map(tableName => actualTables.find(t => t.name === tableName))
.filter((t): t is Table => t !== undefined);
}
}

Expand Down

0 comments on commit 98f0c9d

Please sign in to comment.