Skip to content

Commit a761e7e

Browse files
committed
fix: return auto-increment as generated
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
1 parent 49b33f8 commit a761e7e

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

lib/discovery.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function mixinDiscovery(PostgreSQL) {
137137
results.map(function(r) {
138138
// PostgreSQL returns ALWAYS in case the property is generated,
139139
// otherwise it returns NEVER
140-
if (r.generated === 'ALWAYS') {
140+
if (r.generated === 'ALWAYS' || r.identityGenerated === 'ALWAYS') {
141141
r.generated = true;
142142
} else {
143143
r.generated = false;
@@ -173,8 +173,9 @@ function mixinDiscovery(PostgreSQL) {
173173
if (owner) {
174174
sql = this.paginateSQL('SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName",'
175175
+ 'data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
176+
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable",'
176177
+ ' is_generated AS "generated",'
177-
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
178+
+ ' identity_generation AS "identityGenerated"'
178179
+ ' FROM information_schema.columns'
179180
+ ' WHERE table_schema=\'' + owner + '\''
180181
+ (table ? ' AND table_name=\'' + table + '\'' : ''),
@@ -183,8 +184,9 @@ function mixinDiscovery(PostgreSQL) {
183184
sql = this.paginateSQL('SELECT current_schema() AS "owner", table_name AS "tableName",'
184185
+ ' column_name AS "columnName",'
185186
+ ' data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
187+
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable",'
186188
+ ' is_generated AS "generated",'
187-
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
189+
+ ' identity_generation AS "identityGenerated"'
188190
+ ' FROM information_schema.columns'
189191
+ (table ? ' WHERE table_name=\'' + table + '\'' : ''),
190192
'table_name, ordinal_position', {});

test/postgresql.discover.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ describe('Discover LDL schema from a table', function() {
382382
done(null, schema);
383383
});
384384
});
385+
386+
it('should return an LDL schema for user which has id as generated', function(done) {
387+
db.discoverSchema('user', {owner: 'strongloop'}, function(err, schema) {
388+
console.log('This is our err: ', err);
389+
console.log('This is our schema: ', schema);
390+
assert(schema.properties.id.generated);
391+
assert(typeof schema.properties.id.generated === 'boolean');
392+
done(null, schema);
393+
});
394+
});
385395
});
386396

387397
describe('Discover and map correctly database types', function() {

test/schema.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,15 @@ CREATE TABLE "GeoPoint" (
267267
);
268268

269269

270+
--
271+
-- Name: user; Type: TABLE; Schema: strongloop; Owner: strongloop
272+
--
273+
274+
CREATE TABLE "user" (
275+
id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
276+
email character varying(100)
277+
);
278+
270279
--
271280
-- Name: GeoPoint_id_seq; Type: SEQUENCE; Schema: strongloop; Owner: strongloop
272281
--

0 commit comments

Comments
 (0)