Skip to content

Commit 6fcd36d

Browse files
committedJul 10, 2023
feat(bigserial): support BIGSERIAL when using autoIncrement with bigint type
Signed-off-by: Jéssica Schissato <jessicaschissato@gmail.com>
1 parent b64a02a commit 6fcd36d

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ var PgDriver = Base.extend({
340340

341341
if (spec.primaryKey) {
342342
if (spec.autoIncrement) {
343-
constraint.push('SERIAL');
343+
constraint.push(spec.type === this.type.BIGINT ? 'BIGSERIAL' : 'SERIAL');
344344
}
345345

346346
if (options.emitPrimaryKey) {

‎test/pg_test.js

+46
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,52 @@ vows
243243
}
244244
}
245245
})
246+
.addBatch({
247+
autoIncrement: {
248+
topic: function () {
249+
db.createTable(
250+
'event',
251+
{
252+
id: {
253+
type: dataType.BIG_INTEGER,
254+
primaryKey: true,
255+
autoIncrement: true
256+
}
257+
},
258+
this.callback.bind(this)
259+
);
260+
},
261+
262+
'has column metadata': {
263+
topic: function () {
264+
dbmeta(
265+
'pg',
266+
{ connection: db.connection },
267+
function (err, meta) {
268+
if (err) {
269+
return this.callback(err);
270+
}
271+
meta.getColumns('event', this.callback);
272+
}.bind(this)
273+
);
274+
},
275+
276+
'with auto increment column': function (err, columns) {
277+
assert.isNull(err);
278+
var column = findByName(columns, 'id');
279+
assert.strictEqual(column.getDataType(), 'BIGINT');
280+
assert.strictEqual(column.getDefaultValue(), "nextval('event_id_seq'::regclass)")
281+
assert.strictEqual(column.isPrimaryKey(), true);
282+
assert.strictEqual(column.isNullable(), false);
283+
assert.strictEqual(column.isAutoIncrementing(), true);
284+
}
285+
},
286+
287+
teardown: function () {
288+
db.dropTable('event', this.callback);
289+
}
290+
}
291+
})
246292
.addBatch({
247293
dropTable: {
248294
topic: function () {

0 commit comments

Comments
 (0)
Please sign in to comment.