-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Hard to upgrade from v9.0.1
#3290
Comments
I don't like adding config options for this purpose. We should provide better migration paths, instead: Docs, Tools, anything that helps the actual migration.
Could this be (partly) automated with dynamic SQL to create the computed relationships? |
Yeah, I don't like it either. It also provides an easy way to have incompatible outputs between postgREST APIs, that could cause trouble.
I was thinking we could have a |
No need for another CLI flag, we already have everything we need: postgrest-with-postgresql-16 -f test/spec/fixtures/load.sql postgrest-run --dump-schema \
| jq '.dbRelationships | .[] | .[1] | .[] | select(.relCardinality.tag == "O2O")' |
Just using Removing some unnecessary keys: postgrest-with-postgresql-16 -f test/spec/fixtures/load.sql postgrest-run --dump-schema \
| jq '.dbRelationships | .[] | .[1] | .[] | select(.relCardinality.tag == "O2O")' \
| jq 'del(.relFTableIsView,.relTableIsView,.tag,.relIsSelf)' We get an output like: {
"relCardinality": {
"relColumns": [
[
"id",
"id"
],
[
"code",
"code"
]
],
"relCons": "students_info_id_code_fkey",
"tag": "O2O"
},
"relForeignTable": {
"qiName": "students",
"qiSchema": "test"
},
"relTable": {
"qiName": "students_info",
"qiSchema": "test"
}
}
{
"relCardinality": {
"relColumns": [
[
"id",
"id"
],
[
"code",
"code"
]
],
"relCons": "students_info_id_code_fkey",
"tag": "O2O"
},
"relForeignTable": {
"qiName": "students_info",
"qiSchema": "test"
},
"relTable": {
"qiName": "students",
"qiSchema": "test"
}
} The relevant information is there though it's cumbersome with a lot of o2o. And we need to define computed rels for both ends.. Next steps:
Edit: jq expression that aggregates the objects into an array postgrest-with-postgresql-16 -f test/spec/fixtures/load.sql postgrest-run --dump-schema \
| jq '[.dbRelationships | .[] | .[1] | .[] | select(.relCardinality.tag == "O2O" and .relFTableIsView == false and .relTableIsView == false) | del(.relFTableIsView,.relTableIsView,.tag,.relIsSelf)]' |
Surely you mean the v10 release artifacts, because that's where the breaking changes were introduced, right? |
We need to create two computed rels, an -- students -> students_info o2m
create function students_info(students) returns setof students_info rows 1000 as $$
select * from students_info where id = $1.id and code = $1.code
$$ language sql;
-- students_info -> students m2o
create function students(students_info) returns setof students rows 1 as $$
select * from students where id = $1.id and code = $1.code
$$ language sql;
But there's a problem with the schema cache json output. It doesn't show on which table is the foreign key defined. So we cannot know to which table the "many" end belongs to. So the current output is insufficient for having this automated 😞. Maybe the problem is that we add the relationship and the inverse relationship. If we only had one then this should be solvable. Edit: the simplest solution would be to add an attribute to |
I was having a similar issue when working on #3226, since we need to know to which table to insert first in a
So I think this solution would be necessary anyways. |
For this issue it doesn't seem worth it changing the Relationship type. Will close with #3312.
I agree. That could be a |
Problem
v10.0.0 introduced one-to-one relationship detection #2439, which changed the json output of responses using resource embedding. For upgrading, adding computed relationships was recommended but this is considerable work for projects that have many tables. For this reason some projects are stuck on
v9.0.1
.Proposal
The following config can be used to determine which relationships will be represented as json objects. By default it will be:
So projects stuck on
9.0.1
can do:Related
The text was updated successfully, but these errors were encountered: