-
-
Save calvinmetcalf/1aae3ca1eca6d54a3c5a1c74471a7874 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('pg_constraint.conname', 'pg_class.relname') | |
.where('contype', '=', 'f') | |
.join('pg_class').on('pg_class.oid', 'pg_constraint.conrelid'); | |
return Promise.all(foreignKeys.map(({relname, conname}) => | |
knex.schema.raw(` | |
ALTER TABLE ?? | |
ALTER CONSTRAINT ?? | |
DEFERRABLE INITIALLY DEFERRED; | |
`, [relname, conname]) | |
)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment