Created
June 18, 2017 01:12
-
-
Save scf4/03780af508218200a590959d8258f61c 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
export default async (knex) => { | |
const foreignKeys = await knex('pg_constraint') | |
.select('*') | |
.where('contype', '=', 'f'); | |
const queries = foreignKeys.map(async foreignKey => { | |
const [keyData] = await knex('pg_class') | |
.select('relname') | |
.where('oid', '=', foreignKey.conrelid); | |
const tableName = keyData.relname; | |
return knex.schema.raw(` | |
ALTER TABLE "${tableName}" | |
ALTER CONSTRAINT ${foreignKey.conname} | |
DEFERRABLE INITIALLY DEFERRED; | |
`); | |
}); | |
await Promise.all(queries); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment