Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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