Skip to content


Subversion checkout URL

You can clone with
Download ZIP


handle unique constraints in changeColumn() for postgres #46

merged 1 commit into from

2 participants


There doesn't seem to be support for unique constraints passed to the changeColumn() function for the Postgres backend; they just get ignored. I added support for it. Please pull this change into your repo.


Any chance you'd be willing to add a test for that so it doesn't slip through the cracks again in the future? If not, I can write one, but I might not get to it right away.


I can probably figure out how to do that. I'll try to get to it today.

@kunklejr kunklejr merged commit 394e342 into db-migrate:master

Fix is in version 0.2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 1 deletion.
  1. +20 −1 lib/driver/pg.js
21 lib/driver/pg.js
@@ -116,7 +116,26 @@ var PgDriver = Base.extend({
function setNotNull() {
var setOrDrop = columnSpec.notNull === true ? 'SET' : 'DROP';
var sql = util.format("ALTER TABLE %s ALTER COLUMN %s %s NOT NULL", tableName, columnName, setOrDrop);
- this.runSql(sql, setDefaultValue.bind(this));
+ this.runSql(sql, setUnique.bind(this));
+ }
+ function setUnique(err) {
+ if (err) {
+ callback(err);
+ }
+ var sql;
+ var constraintName = tableName + '_' + columnName + '_unique';
+ if (columnSpec.unique === true) {
+ sql = util.format("ALTER TABLE %s ADD CONSTRAINT %s UNIQUE (%s)", tableName, constraintName, columnName);
+ this.runSql(sql, setDefaultValue.bind(this));
+ } else if (columnSpec.unique === false) {
+ sql = util.format("ALTER TABLE %s DROP CONSTRAINT %s", tableName, constraintName);
+ this.runSql(sql, setDefaultValue.bind(this));
+ }
function setDefaultValue(err) {
Something went wrong with that request. Please try again.