Skip to content

Commit

Permalink
fix(changeColumn): chain, not callbacks for passthrough
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Gurtzick <[email protected]>
  • Loading branch information
wzrdtales committed Apr 15, 2020
1 parent 40a1f57 commit ebe88a0
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ var PgDriver = Base.extend({
callback = null;
}

return setNotNull.call(this);
return setNotNull.call(this).nodeify(callback);

function setNotNull() {
var setOrDrop = columnSpec.notNull === true ? 'SET' : 'DROP';
Expand All @@ -466,14 +466,10 @@ var PgDriver = Base.extend({
setOrDrop
);

return this.runSql(sql).nodeify(setUnique.bind(this));
return this.runSql(sql).then(setUnique.bind(this));
}

function setUnique(err) {
if (err) {
return Promise.reject(err);
}

function setUnique() {
var sql;
var constraintName = tableName + '_' + columnName + '_key';

Expand All @@ -484,24 +480,20 @@ var PgDriver = Base.extend({
constraintName,
columnName
);
return this.runSql(sql).nodeify(setDefaultValue.bind(this));
return this.runSql(sql).then(setDefaultValue.bind(this));
} else if (columnSpec.unique === false) {
sql = util.format(
'ALTER TABLE "%s" DROP CONSTRAINT "%s"',
tableName,
constraintName
);
return this.runSql(sql).nodeify(setDefaultValue.bind(this));
return this.runSql(sql).then(setDefaultValue.bind(this));
} else {
return setDefaultValue.call(this);
}
}

function setDefaultValue(err) {
if (err) {
return Promise.reject(err).nodeify(callback);
}

function setDefaultValue() {
var sql;

if (columnSpec.defaultValue !== undefined) {
Expand All @@ -524,9 +516,7 @@ var PgDriver = Base.extend({
columnName
);
}
return this.runSql(sql)
.then(setType.bind(this))
.nodeify(callback);
return this.runSql(sql).then(setType.bind(this));
}

function setType() {
Expand Down

0 comments on commit ebe88a0

Please sign in to comment.