From 6fcd36d6dc4ce727f5f4c584f60f82e20e392b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9ssica=20Schissato?= Date: Sun, 9 Jul 2023 16:25:46 -0400 Subject: [PATCH] feat(bigserial): support BIGSERIAL when using autoIncrement with bigint type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jéssica Schissato --- index.js | 2 +- test/pg_test.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a5b391a..5f97b18 100644 --- a/index.js +++ b/index.js @@ -340,7 +340,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) { diff --git a/test/pg_test.js b/test/pg_test.js index 1ed7b16..bc55c30 100644 --- a/test/pg_test.js +++ b/test/pg_test.js @@ -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 () {