Created
May 18, 2019 05:35
-
-
Save aizatto/6428f9a2a5191126d62a9c35f37a8dc5 to your computer and use it in GitHub Desktop.
knex: Migrate from MySQL to PostgreSQL
This file contains hidden or 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
const pg = require('pg'); | |
pg.defaults.ssl = true; | |
const configs = require("config/knexfile.js"); | |
const mysql = require("knex")(configs["mysql"]); | |
const postgres = require("knex")(configs["postgres"]); | |
async function migrate(table) { | |
const results = await mysql.from(table); | |
await postgres(table).insert(results); | |
} | |
(async () => { | |
await migrate("users"); | |
await migrate("entries"); | |
await migrate("tags"); | |
await migrate("entry_to_tag"); | |
})().catch(err => { | |
console.error(err); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This don't working