Skip to content

Commit

Permalink
qualify table names in configuration query (#136)
Browse files Browse the repository at this point in the history
### What

We want to emit table and views collection names as qualified (with the
schema name) in the configuration generation, so that when there the are
multiple tables with the same name but different schemas, the collection
names won't clash.

### How

In `configuration_query.sql`:

```patch
- rel.relation_name,
+ s.schema_name || '_' || rel.relation_name,
```

The rest of the changes are regenerating the configuration and updating
the tests to use the qualified names.
  • Loading branch information
soupi committed Nov 3, 2023
1 parent 32ac9f8 commit ccd4446
Show file tree
Hide file tree
Showing 99 changed files with 1,285 additions and 1,275 deletions.
2 changes: 1 addition & 1 deletion benchmarks/component/benchmarks/select-by-pk.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const testid = "select-by-pk";
const agentSocket = __ENV.AGENT_SOCKET || "localhost:8100";
const url = `http://${agentSocket}/query`;
const data = {
collection: "Album",
collection: "public_Album",
query: {
fields: {
id: { type: "column", column: "AlbumId", arguments: {} },
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/component/benchmarks/select-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const testid = "select-variables";
const agentSocket = __ENV.AGENT_SOCKET || "localhost:8100";
const url = `http://${agentSocket}/query`;
const data = {
collection: "Album",
collection: "public_Album",
query: {
fields: {
Title: {
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/component/benchmarks/select-where.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const testid = "select-where";
const agentSocket = __ENV.AGENT_SOCKET || "localhost:8100";
const url = `http://${agentSocket}/query`;
const data = {
collection: "Album",
collection: "public_Album",
query: {
fields: {
id: { type: "column", column: "AlbumId", arguments: {} },
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/component/benchmarks/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const testid = "select";
const agentSocket = __ENV.AGENT_SOCKET || "localhost:8100";
const url = `http://${agentSocket}/query`;
const data = {
collection: "Album",
collection: "public_Album",
query: {
fields: {
id: { type: "column", column: "AlbumId", arguments: {} },
Expand Down
2 changes: 1 addition & 1 deletion crates/connectors/ndc-postgres/src/configuration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ FROM
-- Tables and views
SELECT
jsonb_object_agg(
rel.relation_name,
s.schema_name || '_' || rel.relation_name,
jsonb_build_object(
'schemaName',
s.schema_name,
Expand Down
3 changes: 2 additions & 1 deletion crates/connectors/ndc-postgres/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ impl connector::Connector for Postgres {
configuration::RawConfiguration::empty()
}

/// Configure a configuration maybe?
/// Use the information inside a raw configuration to access the database and query
/// the metadata. Return this information.
async fn update_configuration(
args: Self::RawConfiguration,
) -> Result<Self::RawConfiguration, connector::UpdateConfigurationError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ expression: result
"rows": [
{
"track": "Grito De Alerta",
"Album": {
"public_Album": {
"rows": [
{
"album": "Meus Momentos",
"Artist": {
"public_Artist": {
"rows": [
{
"artist": "Gonzaguinha"
Expand All @@ -24,11 +24,11 @@ expression: result
},
{
"track": "Não Dá Mais Pra Segurar (Explode Coração)",
"Album": {
"public_Album": {
"rows": [
{
"album": "Meus Momentos",
"Artist": {
"public_Artist": {
"rows": [
{
"artist": "Gonzaguinha"
Expand All @@ -41,11 +41,11 @@ expression: result
},
{
"track": "Começaria Tudo Outra Vez",
"Album": {
"public_Album": {
"rows": [
{
"album": "Meus Momentos",
"Artist": {
"public_Artist": {
"rows": [
{
"artist": "Gonzaguinha"
Expand All @@ -58,11 +58,11 @@ expression: result
},
{
"track": "O Que É O Que É ?",
"Album": {
"public_Album": {
"rows": [
{
"album": "Meus Momentos",
"Artist": {
"public_Artist": {
"rows": [
{
"artist": "Gonzaguinha"
Expand All @@ -75,11 +75,11 @@ expression: result
},
{
"track": "Sangrando",
"Album": {
"public_Album": {
"rows": [
{
"album": "Meus Momentos",
"Artist": {
"public_Artist": {
"rows": [
{
"artist": "Gonzaguinha"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ expression: result
"rows": [
{
"Title": "Let There Be Rock",
"Artist": {
"public_Artist": {
"rows": [
{
"Name": "AC/DC"
Expand All @@ -17,7 +17,7 @@ expression: result
},
{
"Title": "Big Ones",
"Artist": {
"public_Artist": {
"rows": [
{
"Name": "Aerosmith"
Expand All @@ -27,7 +27,7 @@ expression: result
},
{
"Title": "Jagged Little Pill",
"Artist": {
"public_Artist": {
"rows": [
{
"Name": "Alanis Morissette"
Expand All @@ -37,7 +37,7 @@ expression: result
},
{
"Title": "Facelift",
"Artist": {
"public_Artist": {
"rows": [
{
"Name": "Alice In Chains"
Expand All @@ -47,7 +47,7 @@ expression: result
},
{
"Title": "Warner 25 Anos",
"Artist": {
"public_Artist": {
"rows": [
{
"Name": "Antônio Carlos Jobim"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ expression: result
"rows": [
{
"0Title": "For Those About To Rock We Salute You",
"Artist": {
"public_Artist": {
"rows": [
{
"0ArtistId": 1,
"Albums": {
"rows": [
{
"0Title": "For Those About To Rock We Salute You",
"Artist": {
"public_Artist": {
"rows": [
{
"0Name": "AC/DC"
Expand All @@ -29,7 +29,7 @@ expression: result
},
{
"0Title": "Let There Be Rock",
"Artist": {
"public_Artist": {
"rows": [
{
"0Name": "AC/DC"
Expand All @@ -45,15 +45,15 @@ expression: result
},
{
"0Title": "Let There Be Rock",
"Artist": {
"public_Artist": {
"rows": [
{
"0ArtistId": 1,
"Albums": {
"rows": [
{
"0Title": "For Those About To Rock We Salute You",
"Artist": {
"public_Artist": {
"rows": [
{
"0Name": "AC/DC"
Expand All @@ -63,7 +63,7 @@ expression: result
},
{
"0Title": "Let There Be Rock",
"Artist": {
"public_Artist": {
"rows": [
{
"0Name": "AC/DC"
Expand All @@ -86,15 +86,15 @@ expression: result
"rows": [
{
"0Title": "Balls to the Wall",
"Artist": {
"public_Artist": {
"rows": [
{
"0ArtistId": 2,
"Albums": {
"rows": [
{
"0Title": "Balls to the Wall",
"Artist": {
"public_Artist": {
"rows": [
{
"0Name": "Accept"
Expand All @@ -104,7 +104,7 @@ expression: result
},
{
"0Title": "Restless and Wild",
"Artist": {
"public_Artist": {
"rows": [
{
"0Name": "Accept"
Expand All @@ -120,15 +120,15 @@ expression: result
},
{
"0Title": "Restless and Wild",
"Artist": {
"public_Artist": {
"rows": [
{
"0ArtistId": 2,
"Albums": {
"rows": [
{
"0Title": "Balls to the Wall",
"Artist": {
"public_Artist": {
"rows": [
{
"0Name": "Accept"
Expand All @@ -138,7 +138,7 @@ expression: result
},
{
"0Title": "Restless and Wild",
"Artist": {
"public_Artist": {
"rows": [
{
"0Name": "Accept"
Expand All @@ -161,15 +161,15 @@ expression: result
"rows": [
{
"0Title": "Big Ones",
"Artist": {
"public_Artist": {
"rows": [
{
"0ArtistId": 3,
"Albums": {
"rows": [
{
"0Title": "Big Ones",
"Artist": {
"public_Artist": {
"rows": [
{
"0Name": "Aerosmith"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ expression: result
"rows": [
{
"Name": "A Copland Celebration, Vol. I",
"Artist": {
"public_Artist": {
"rows": [
{
"Name": "Aaron Copland & London Symphony Orchestra"
Expand All @@ -17,7 +17,7 @@ expression: result
},
{
"Name": "Worlds",
"Artist": {
"public_Artist": {
"rows": [
{
"Name": "Aaron Goldberg"
Expand All @@ -27,7 +27,7 @@ expression: result
},
{
"Name": "Sir Neville Marriner: A Celebration",
"Artist": {
"public_Artist": {
"rows": [
{
"Name": "Academy of St. Martin in the Fields Chamber Ensemble & Sir Neville Marriner"
Expand All @@ -37,7 +37,7 @@ expression: result
},
{
"Name": "Fauré: Requiem, Ravel: Pavane & Others",
"Artist": {
"public_Artist": {
"rows": [
{
"Name": "Academy of St. Martin in the Fields, John Birch, Sir Neville Marriner & Sylvia McNair"
Expand All @@ -47,7 +47,7 @@ expression: result
},
{
"Name": "The World of Classical Favourites",
"Artist": {
"public_Artist": {
"rows": [
{
"Name": "Academy of St. Martin in the Fields & Sir Neville Marriner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ FROM
FROM
(
SELECT
"%0_Album"."Title" AS "Title"
"%0_public_Album"."Title" AS "Title"
FROM
"public"."Album" AS "%0_Album"
"public"."Album" AS "%0_public_Album"
WHERE
("%0_Album"."AlbumId" = 35)
("%0_public_Album"."AlbumId" = 35)
) AS "%2_rows"
) AS "%2_rows"
) AS "%1_universe"
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ FROM
FROM
(
SELECT
"%0_Album"."Title" AS "Title"
"%0_public_Album"."Title" AS "Title"
FROM
"public"."Album" AS "%0_Album"
"public"."Album" AS "%0_public_Album"
WHERE
("%0_Album"."Title" !~~* cast($1 as varchar))
(
"%0_public_Album"."Title" !~~* cast($1 as varchar)
)
ORDER BY
"%0_Album"."AlbumId" ASC
"%0_public_Album"."AlbumId" ASC
LIMIT
5
) AS "%2_rows"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ FROM
FROM
(
SELECT
"%0_Album"."Title" AS "Title"
"%0_public_Album"."Title" AS "Title"
FROM
"public"."Album" AS "%0_Album"
"public"."Album" AS "%0_public_Album"
WHERE
("%0_Album"."Title" ~~ cast($1 as varchar))
("%0_public_Album"."Title" ~~ cast($1 as varchar))
ORDER BY
"%0_Album"."AlbumId" ASC
"%0_public_Album"."AlbumId" ASC
) AS "%2_rows"
) AS "%2_rows"
) AS "%1_universe"
Loading

0 comments on commit ccd4446

Please sign in to comment.