Skip to content

Commit

Permalink
Merge pull request #77 from jessicaschissato/bigserial
Browse files Browse the repository at this point in the history
feat(bigserial): support BIGSERIAL when using autoIncrement with bigint type
  • Loading branch information
wzrdtales authored Sep 10, 2023
2 parents bb6a90d + 6fcd36d commit f01df9a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ var PgDriver = Base.extend({

if (spec.primaryKey) {
if (spec.autoIncrement) {
constraint.push('SERIAL');
constraint.push(spec.type === this.type.BIGINT ? 'BIGSERIAL' : 'SERIAL');
}

if (options.emitPrimaryKey) {
Expand Down
46 changes: 46 additions & 0 deletions test/pg_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,52 @@ vows
}
}
})
.addBatch({
autoIncrement: {
topic: function () {
db.createTable(
'event',
{
id: {
type: dataType.BIG_INTEGER,
primaryKey: true,
autoIncrement: true
}
},
this.callback.bind(this)
);
},

'has column metadata': {
topic: function () {
dbmeta(
'pg',
{ connection: db.connection },
function (err, meta) {
if (err) {
return this.callback(err);
}
meta.getColumns('event', this.callback);
}.bind(this)
);
},

'with auto increment column': function (err, columns) {
assert.isNull(err);
var column = findByName(columns, 'id');
assert.strictEqual(column.getDataType(), 'BIGINT');
assert.strictEqual(column.getDefaultValue(), "nextval('event_id_seq'::regclass)")
assert.strictEqual(column.isPrimaryKey(), true);
assert.strictEqual(column.isNullable(), false);
assert.strictEqual(column.isAutoIncrementing(), true);
}
},

teardown: function () {
db.dropTable('event', this.callback);
}
}
})
.addBatch({
dropTable: {
topic: function () {
Expand Down

0 comments on commit f01df9a

Please sign in to comment.