-
-
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
multiple schemas in one instance #1450
multiple schemas in one instance #1450
Conversation
b3c584a
to
e9e4d56
Compare
@MahmoudKassem Regarding your issue on #1436 (comment)
What I've done is to reject the request at the http level(it doesn't hit the database, so no need for tailoring an invalid sql query). I've taken into account the Accept-Profile proposal recommendations: If the server cannot process the specified profile, it would answer with an http 406 status code and possibly a list of acceptable profiles. So, if the user specifies an invalid schema he'll get an error:
I've also solved the dbstructure issue(mentioned in #1436 (comment)). Let me know what you think. |
e9e4d56
to
2bbbb9b
Compare
@steve-chavez great job! Now all that's left is the OpenAPI test, right? Will try to get them done tomorrow. |
@MahmoudKassem I've noticed that with the (Edit: Actually, I've noted that it's possible to do this with the same However If we fully adopt the Content Negotiation by Profile spec we could have that working by doing:
That would make an insert to the For now, you adding the missing OpenAPI tests would be great. |
To fully adopt the profile negotiation spec, we would need to implement two requests: list profiles and get resource by profile. I'm asking some questions to the workgroup(w3c/dx-connegp#15 and w3c/dx-connegp#18) for how to do this correctly. As it is now, we can implement only the "get resource by profile" part(the I'd like to move forward and make a new release. We can work on supporting "list profiles" after the release and for now we'll make a note in the docs about it being a work in progress. |
@steve-chavez the test is failing because it is omitting the "value" object in the properties as well as the "value" key in the "required" array, not sure what's wrong. |
@steve-chavez in my local database(not the one created for the tests) the fields where marked as not null that's why they were showing up in the required field when calling the service with curl. Now that error is gone, but I don't understand why the values are omitted under "properties". |
I also don't have a clue why the |
My only guess for now is that the DbStructure doesn't contain the columns( |
Ahhh.. here's the culprit: Lines 58 to 60 in de218e9
In the test suite the DbStructure is only loading the "test" schema. This needs refactoring so it doesn't happen again when testing other schemas. |
@steve-chavez thank you for finding the issue, now that this is addressed its time to take a look at "get resource by profile" implementation. |
@MahmoudKassem Regarding "get resource by profile", for GET/HEAD should be simple. Basically: GET /table
Accept-Profile: v1
HTTP/1.1 200 OK
Content-Profile: v1
body here That is, when For POST/PATCH/PUT/DELETE, the implementation should be: POST /table
Content-Profile: v1
body here
HTTP/1.1 201 Created That should also be straightforward but there's a catch here. Suppose we have a Should we allow to POST a payload to a v1.table and respond with a v2.table representation? In theory, this could be done with the following headers: POST /table
Content-Profile: v1
Accept-Profile: v2
Prefer: return=representation
body here For now I think we should not allow this and keep it simple. If a POST request with |
…mportant to note that the db-schema can still be used as usual what has been added is the possibility to query different schemas by specifying them in the uri postgrest-host:postgrest-port/schema/table. Another important note is that the extensions only includes the functionality itself the OpenAPI generation is only available for the schema specified in db-schema
…ed by comma. The dynamic schema is now passed via header instead of uri and it has to be one of the values of db-schema otherwise the default schema will be used which is the first value of db-schema.
… header. Inputing a schema not existing in th db-schema configuration parameter will now result in an 404 Not Found instead of falling back to the default schema which is the first value of db-schema.
…h previous version
Just a note here, on how to implement the "list profiles" part. First we would need a way to get the metadata for a single resource. Right now we offer metadata for all resources at the root. This was also requested in #1421. I'm thinking that the link for getting a GET /?resource=table&_profile=v1 (Borrowing the This would give a filtered openapi output. Basically, the openapi Once we have that, "list profiles" would be done with OPTIONS: OPTIONS /table
Accept: application/json, ...
Accept-Profile:
/?resource=table&_profile=v1;
rel="canonical";
token="v1",
/?resource=table&_profile=v2;
rel="alternate";
token="v2" (I'm using relative URLs there, but they could be absolute like Once we have that I think we would be in compliance with the spec. It can be done in a later PR after #1421 is solved. |
Come to think of it, if we list profiles with OPTIONS that would also solve #790. Funny that #790 (comment) also mentioned the profile spec as a possible solution. Though it was an older one where the profile could only be specified in the media type. |
I've added a condition for checking profile negotiation is only possible when multiple schemas are specified. This is to ensure that users that would like to keep using a single schema don't see the Tests that are missing: POST/PATCH/PUT/DELETE, calling a stored proc and maybe a resource embedding one to ensure it all works normally. |
938323a
to
a249cff
Compare
I think I've finished my work here. The tests should cover all of the http verbs. @MahmoudKassem Could you give it a final review and add an entry to the CHANGELOG? |
@steve-chavez Everything looks fine to me, sorry for being so inactive things have been crazy lately and thank you for all your efforts, patience and all that I have learned. Glad to see this feature being seen through. I've added an entry to CHANGELOG.md , if you want to add something please feel free to do so. |
@MahmoudKassem Thanks a lot for your work and help here. Without your initiative this feature wouldn't have been done by now. So I'm also giving you credit on the CHANGELOG. I'll merge and make a new release 🚀 |
The schema to use can be selected through the headers `Accept-Profile` for GET/HEAD and `Content-Profile` for POST/PATCH/PUT/DELETE. This is based on the https://www.w3.org/TR/dx-prof-conneg/ttps://www.w3.org/TR/dx-prof-conneg/ spec. Also increase all memory tests by 1M(otherwise CI fails). Co-authored-by: Mahmoud Kassem <[email protected]> Co-authored-by: Mahmoud Kassem <[email protected]>
The schema to use can be selected through the headers `Accept-Profile` for GET/HEAD and `Content-Profile` for POST/PATCH/PUT/DELETE. This is based on the https://www.w3.org/TR/dx-prof-conneg/ttps://www.w3.org/TR/dx-prof-conneg/ spec. Also increase all memory tests by 1M(otherwise CI fails). Co-authored-by: Mahmoud Kassem <[email protected]> Co-authored-by: Mahmoud Kassem <[email protected]>
Continuing the work on #1436.