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

Commit

Permalink
[FIX] Sort views after tables
Browse files Browse the repository at this point in the history
Closes #65
Closes #66
  • Loading branch information
marco-fp authored and bradzacher committed Mar 24, 2019
1 parent d2c2c57 commit 0926aa6
Show file tree
Hide file tree
Showing 3 changed files with 2,049 additions and 2,033 deletions.
14 changes: 9 additions & 5 deletions dist/mysqldump.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface ConnectionOptions {
/**
* Optional PEM formatted CRLs (Certificate Revocation Lists).
*/
crl?: string | string[];
crl?: string | Array<string>;
/**
* Attempt to use the server's cipher suite preferences instead of the client's.
*/
Expand Down Expand Up @@ -161,6 +161,10 @@ export interface DataDumpOptions {
* Defaults to true.
*/
format?: boolean;
/**
* Include file headers in output
*/
verbose?: boolean;
/**
* Dump data from views.
* Defaults to false.
Expand Down Expand Up @@ -196,7 +200,7 @@ export interface DumpOptions {
* The list of tables that you want to dump.
* Defaults to all tables (signalled by passing an empty array).
*/
tables?: string[];
tables?: Array<string>;
/**
* True to use the `tables` options as a blacklist, false to use it as a whitelist.
* Defaults to false.
Expand Down Expand Up @@ -270,15 +274,15 @@ export interface Table {
/**
* An ordered list of columns (for consistently outputing as per the DB definition)
*/
columnsOrdered: string[];
columnsOrdered: Array<string>;
/**
* True if the table is actually a view, false otherwise.
*/
isView: boolean;
/**
* A list of triggers attached to the table
*/
triggers: string[];
triggers: Array<string>;
}
export interface DumpReturn {
/**
Expand All @@ -301,7 +305,7 @@ export interface DumpReturn {
*/
trigger: string | null;
};
tables: Table[];
tables: Array<Table>;
}
export default function main(inputOptions: Options): Promise<DumpReturn>;

Expand Down
12 changes: 12 additions & 0 deletions src/getSchemaDump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ export default async function getSchemaDump(

return s
})
.sort((a, b) => {
// sort the views to be last

if (a.isView && !b.isView) {
return 1
}
if (!a.isView && b.isView) {
return -1
}

return 0
})

return createStatements
}
Loading

0 comments on commit 0926aa6

Please sign in to comment.