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

Postgres database schema generation not maintaining case sensitivity of names and not including the joins based on the referential integrity #120

Closed
dgkm opened this issue Jun 4, 2019 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@dgkm
Copy link
Contributor

dgkm commented Jun 4, 2019

Describe the bug
When generating the schema in the Playground or CLI selecting multiple table names on Postgres is not generating the schema file having the joins automatically based on the referential integrity/foreign key columns.

In addition, schema is not adding quotes to maintain case sensitivity in both the Table name and column names.

To Reproduce
Create tables and columns having case sensitive names with double quotes.

CREATE TABLE "public"."Account"
(
    "id" serial primary key,
    "departmentId" integer REFERENCES "public"."Department"("id") ON DELETE CASCADE,
    "firstName" text,
    "lastName" text,
    "dateOfBirth" date,
    "email" text,
    "status" text,
    "createdAt" timestamptz not null default now(),
    "updatedAt" timestamptz not null default now(),
    "archiveAt" timestamptz not null default now()
)

CREATE TABLE "public"."Department"
(
    "id" serial primary key,
    "name" text,
    "description" text,
    "createdAt" timestamptz not null default now(),
    "updatedAt" timestamptz not null default now(),
    "archiveAt" timestamptz not null default now()
)

Steps to reproduce the behavior

  1. Connect cube.js to 'Postgres' database
  2. Go to 'Playground'
  3. Click on 'Database or Tables'
  4. Select all the 'Tables' then click on generate schema
  5. Click on 'Schema' and open the Schema file

there you see no entries for joins property.

Expected behavior

  1. to maintain the case sensitivity of the table and column names by adding single quotes to the name property values in the schema.

E.g., "Account" for table name and "accountId", "firstName", "lastName", "dataOfBirth" for column names.

  1. To populate the joins automatically primary, referential integrity columns in a mixed case sensitivity setup.

E.g., having table name as "Account" and reference column as "accountId" rather than "AccountId".

Version:
Latest

@dgkm dgkm changed the title PostGres schema generation not including the joins based on the referential integrity Postgres database schema generation not maintaining case sensitivity of names and not including the joins based on the referential integrity Jun 4, 2019
@paveltiunov
Copy link
Member

@dgkmurthy Hey Keshava! Thanks for posting this! Yep. Here we should have lowercase comparison:
https://github.com/statsbotco/cube.js/blob/a53f0136e3efd2c4cf0ad52bec033319e6966438/packages/cubejs-schema-compiler/scaffolding/ScaffoldingSchema.js#L155

@paveltiunov paveltiunov added the bug Something isn't working label Jun 4, 2019
@dgkm
Copy link
Contributor Author

dgkm commented Jun 5, 2019

Fixed in #122

dgkm added a commit to dgkm/cube.js that referenced this issue Jun 5, 2019
for case sensitive table and column names
Issue: cube-js#120
paveltiunov pushed a commit that referenced this issue Jun 5, 2019
…umn names (#124)

* Bug Fixes:
  - Schema generator bug with case sensitive Table and Column names
  - Column name ambiguity issue during table joins with similar column names fix by forcing the alias for column names
 - Query bug fix to mandatorily include double quotes for the alias when running query against table names with restricted keywords
 such as "case"

* Revert "Bug Fixes:"

This reverts commit a0b304e.

* Bug Fix:  Schema generator bug with case sensitive Table and Column names
Issue #120

* Bug Fix: Issue with generting joins in the schema
for case sensitive table and column names
Issue: #120

* Escape Names and RegExp for filter

* Regex pattern update
@paveltiunov paveltiunov added this to the v0.9.13 milestone Jun 6, 2019
dgkm added a commit to dgkm/cube.js that referenced this issue Jun 6, 2019
  - Schema generator bug with case sensitive Table and Column names
  - Column name ambiguity issue during table joins with similar column names fix by forcing the alias for column names
 - Query bug fix to mandatorily include double quotes for the alias when running query against table names with restricted keywords
 such as "case"

Revert "Bug Fixes:"

This reverts commit a0b304e.

Bug Fix:  Schema generator bug with case sensitive Table and Column names
Issue cube-js#120

Bug Fix: Issue with generting joins in the schema
for case sensitive table and column names
Issue: cube-js#120

Escape Names and RegExp for filter

Regex pattern update

Query bug fix to force to include cube alias in the schema and escape character for the alias when running query against table names with restricted keywords
such as "case"

Used escapeColumnName function instead of
inline escape characters
dgkm added a commit to dgkm/cube.js that referenced this issue Jun 6, 2019
for case sensitive table and column names
Issue: cube-js#120
@craigharman
Copy link

This still seems to be an issue in v0.18.3 with time dimensions and Postgres.
Column name "startTime" gives Error: column tableName.starttime does not exist
Changing the column name to all lowercase fixes the issue.

@paveltiunov
Copy link
Member

@craigharman Hey Craig! Could you please share generated schema?

@craigharman
Copy link

Please see below. Note changing startTime to start_time or starttime and updating database column name accordingly fixes the error.

cube(DeviceConsumption, { sql: SELECT * FROM public."DeviceConsumption"`,

joins: {
Devices: {
sql: ${CUBE}.device_id = ${Devices}.id,
relationship: belongsTo
},

PricingPeriods: {
  sql: `${CUBE}.pricing_period_id = ${PricingPeriods}.id`,
  relationship: `belongsTo`
}

},

measures: {
count: {
type: count,
drillMembers: [id, startTime, endTime]
}
},

dimensions: {
id: {
sql: id,
type: number,
primaryKey: true
},

startTime: {
  sql: `start_time`,
  type: `time`
},

endTime: {
  sql: `end_time`,
  type: `time`
}

}
});`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants