Skip to content

Instantly share code, notes, and snippets.

@0ex-d
Created August 1, 2021 02:47
Show Gist options
  • Save 0ex-d/2418140c87448c49b3ca2427699b9bbf to your computer and use it in GitHub Desktop.
Save 0ex-d/2418140c87448c49b3ca2427699b9bbf to your computer and use it in GitHub Desktop.
/**
* Quick hack to generate migration template into a file
* @author David
* @param {*} files
* @returns {string} SQL template
*/
const SqlTempGenerator = files => {
if (!Array.isArray(files)) throw "Must be an array of SQL files";
let sqlStr = "INSERT INTO migrations (filename) VALUES";
return sqlStr.concat(" ", files.map(file => `('${file}')`).join(","), ";");
};
// from fs.readdir()
const upFiles = [
"/20200610015707-tbl1",
"/20200618082927-tbl2",
];
const INSERT_TEMPLATE = SqlTempGenerator(upFiles);
fs.writeFile('migrations.sql', INSERT_TEMPLATE, err => ...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment