Last active
January 31, 2020 18:43
-
-
Save hos/29e997e7afbf9a688ff3b1088fbc6e15 to your computer and use it in GitHub Desktop.
Script to create schema.sql from sequelize sync logs. This will only help with getting started there must be some other changes to do manually for using with graphile-migrate.
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
import fs from 'fs' | |
export function getLogger (path) { | |
const stream = fs.createWriteStream(path) | |
process.on('beforeExit', () => stream.close()) | |
return msg => { | |
const _ = msg + '' | |
if (!/ select /i.test(_)) { | |
stream.write( | |
_.replace('Executing (default): ', '\n').replace(/;/g, ';\n') | |
) | |
// the rest formating can be done with pg formatter or | |
// with some online free tools. I used https://sqlformat.org | |
} | |
} | |
} | |
/* | |
* After sequelize is synced the rest can be edited manually in schema.sql | |
* export const sequelize = new Sequelize(database.connectionString, { | |
* // ... | |
* logging: getLogger('./schema.sql') | |
* }) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment