-
-
Notifications
You must be signed in to change notification settings - Fork 87
keep the table order of the table whitelist #73
keep the table order of the table whitelist #73
Conversation
e164246
to
81d687d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this give you a false sense of security unless your table structure is an acyclic graph?
As soon as there are potential cycles in your structure, this method is no safer.
I would probably go as far as to say that using this tool to dump a live production database with no locks should be classified as an unsupported use case because there are so many potential foot-guns.
src/getTables.ts
Outdated
); | ||
tables = restrictedTables | ||
.map(tableName => actualTables.find(t => t.name === tableName)) // keeping the order of the passed-in whitelist | ||
.filter(t => Boolean(t)) as Array<Table>; // filter out non-existing tables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should avoid using a type cast unless it's absolutely necessary.
Also you should avoid using the Boolean
constructor because it does too much magic in terms of truthy/falsey coercion.
For filter
, you can annotate with a type predicate
.filter(t => Boolean(t)) as Array<Table>; // filter out non-existing tables | |
// filter out non-existing tables | |
.filter((t): t is Table => t != null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will give you the lint error: Expected '!==' and instead saw '!=' eqeqeq
...
yeah, my use case is for acyclic dependencies for which I can create a correct partial order of the tables, but this would break for true cycles... my last PR about supporting maybe you can provide some |
it seems to me like you want to set your master DB to |
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.
81d687d
to
56aeab7
Compare
1e63360
to
41e802b
Compare
What would be the drawback of merging this PR? |
may I ask you for pushing out a new release containing these changes? |
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.