- Notifications
You must be signed in to change notification settings - Fork1.9k
Description
Description
I’m trying to extract the database schema from a Postgres instance connected to Cube (CubeJS), but none of the approaches I tried work correctly.
My goal is to reliably retrieve tables/columns plusprimary keys and foreign keys, so I can generateData Models programmatically (or at least validate/derive relationships). However:
1)playground/db-schema endpoint
I tried the Playground endpointplayground/db-schema (I understand this might not be intended for production use), but the output doesnot correctly include primary keys or foreign keys. Relationships appear incomplete/incorrect.
2) Queryinginformation_schema via CubeSQL API
I tried using the CubeSQL API endpoint:
POST /cubejs-api/v1/cubesql{"query":"SELECT * FROM information_schema.constraint_column_usage"}
But it returnsno rows at all (empty result), even though the underlying Postgres database definitely has constraints.
3) Importing/using the server library (introspection during cube build)
I also tried importing the server library and noticed the failure seems related toaccessing certain system tables/views (like the example above). When those queries fail or return empty, cubes cannot be built correctly / the introspection-based parts break.
Environment
- Database:PostgreSQL
- Deployment: Docker / Node
- Works the samewith existing Data Models andwithout any Data Models (problem persists either way)
Expected behavior
A supported/reliable way to fetch DB schema metadata from Cube for Postgres, including:
- tables and columns
- primary keys
- foreign keys / relationships
information_schemaqueries should return expected rows when executed via CubeSQL (or clear documentation if they are intentionally blocked).If
playground/db-schemais not intended to be used, guidance on the correct endpoint / recommended approach.
Actual behavior
playground/db-schemareturns incomplete schema data (PK/FK missing or incorrect).SELECT * FROM information_schema.constraint_column_usagevia/cubejs-api/v1/cubesqlreturns no rows.- Introspection seems to fail on certain metadata tables/views, preventing correct cube/data model generation.
Questions
- Is this a known limitation/bug for Postgres schema introspection in Cube?
- Are
information_schema/pg_catalogqueries restricted/filtered when running through CubeSQL? If so, is there a way to allow them? - What is the recommended/supported way to query a database schema through Cube?
- Is there an official way tocreate Data Models programmatically (or generate them from schema metadata) that Cube supports?
Reproduction steps (high level)
Connect Cube to a Postgres DB with PK/FK constraints.
Call
playground/db-schemaand check whether PK/FK are present/correct.Call
/cubejs-api/v1/cubesqlwith:SELECT*FROMinformation_schema.constraint_column_usage;
Observe empty results and incomplete/failed introspection.
Additional info / logs
If needed, I can provide:
- Cube logs around schema introspection / cube build
- Postgres version and sample schema (sanitized)
- The exact Cube config and connection settings