Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return auto-increment as generated #648

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function mixinDiscovery(PostgreSQL) {
results.map(function(r) {
// PostgreSQL returns ALWAYS in case the property is generated,
// otherwise it returns NEVER
if (r.generated === 'ALWAYS') {
if (r.generated === 'ALWAYS' || r.identityGenerated === 'ALWAYS') {
r.generated = true;
} else {
r.generated = false;
Expand Down Expand Up @@ -173,8 +173,9 @@ function mixinDiscovery(PostgreSQL) {
if (owner) {
sql = this.paginateSQL('SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName",'
+ 'data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable",'
+ ' is_generated AS "generated",'
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
+ ' identity_generation AS "identityGenerated"'
+ ' FROM information_schema.columns'
+ ' WHERE table_schema=\'' + owner + '\''
+ (table ? ' AND table_name=\'' + table + '\'' : ''),
Expand All @@ -183,8 +184,9 @@ function mixinDiscovery(PostgreSQL) {
sql = this.paginateSQL('SELECT current_schema() AS "owner", table_name AS "tableName",'
+ ' column_name AS "columnName",'
+ ' data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable",'
+ ' is_generated AS "generated",'
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
+ ' identity_generation AS "identityGenerated"'
+ ' FROM information_schema.columns'
+ (table ? ' WHERE table_name=\'' + table + '\'' : ''),
'table_name, ordinal_position', {});
Expand Down
10 changes: 10 additions & 0 deletions test/postgresql.discover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,16 @@ describe('Discover LDL schema from a table', function() {
done(null, schema);
});
});

it('should return an LDL schema for user which has id as generated', function(done) {
db.discoverSchema('user', {owner: 'strongloop'}, function(err, schema) {
console.log('This is our err: ', err);
console.log('This is our schema: ', schema);
assert(schema.properties.id.generated);
assert(typeof schema.properties.id.generated === 'boolean');
done(null, schema);
});
});
});

describe('Discover and map correctly database types', function() {
Expand Down
9 changes: 9 additions & 0 deletions test/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ CREATE TABLE "GeoPoint" (
);


--
-- Name: user; Type: TABLE; Schema: strongloop; Owner: strongloop
--

CREATE TABLE "user" (
id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
email character varying(100)
);

--
-- Name: GeoPoint_id_seq; Type: SEQUENCE; Schema: strongloop; Owner: strongloop
--
Expand Down