Created
August 1, 2021 02:47
-
-
Save 0ex-d/2418140c87448c49b3ca2427699b9bbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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