A few questions after my first explorations of PostgREST #3952
Replies: 1 comment 4 replies
-
Ideally, one should do the following:
Note, that the latter is rather vague on purpose - because I have not implemented it myself like this, yet.
You need
Personally, I would not use a view for signup. Here's why:
Since I wrote the linked comment an additional "Yes", won't help much. I have triggers on my
We have plenty of open tickets about OpenAPI, which we are not actively working on in the haskell code base anymore*. The goal is to do #1698, so OpenAPI is currently a bit "on hold". That being said, #1870 is tangentially related, because we always show all methods for VIEWs, too - so that would be the same for RPCs as well, I guess.
I have experimented with So yeah, I have a few lessons learned in that area, but nothing open sourced right now. The takeaway for me: I didn't find anything that satisfied my requirements when I started with that a couple of years ago, so rolled my own. I'm curious what the options are nowadays.. or whether it might make sense to build something in this area from scratch.
That's the burning question, all the time, I think. One that, I haven't found the ultimate answer to, yet. My journey through that space was roughly like this:
I have been thinking about a different approach lately. Basically an extension of what I did in #2999 (reply in thread) already, where I recreate most of my database objects (except tables) from scratch on every deployment. What if.. I could recreate the whole database from scratch on every deployment? No migrations anymore, ever. At least not "change the existing table in this and that way". Instead, I'd deploy a new database, build the new schema from scratch and then sync the database via logical replication. OK - now the schema between the two instances differs, so we still need some kind of "migration". We would "only" need a rule to transform data from the old schema into the new schema. This could possibly be expressed as simple A lot of text, but no clear conclusion, sorry :)
Can't help that much here, because I don't trigger async jobs outside the database. I do everything inside. Yes, I do have a bit of python code as well - but I can run that via Hopefully some of that is helpful. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I’ve been working with (Python) backends for many years and it has always felt somewhat bulky and clumsy and verbose to connect an app layer (Python) via an ORM layer (SQLAlchemy) to a database layer (PostgreSQL, previously also MySQL). I must admit: after exploring PostgREST and playing around with it I’m very smitten by its approach!
I do, however, have a few questions and requests for comments as to how to proceed in order to implement this or that requirement. I hope it’s ok to share a bit of code here…
Question 1
Setting up the JWT secret
is discussed here #3765 and I assume still the recommended way of propagating the secret from the environment to both, the PostgreSQL container and PostgREST container? Ideally, I think a single vaulted sources of truth would be best.
Question 2
The section SQL User Management was very helpful but I think a function illustrating user signup would help to complete the picture. I currently use this:
This returns a
200 Ok
but how can I have PostgREST return a201 Created
instead?Is there a general recommendation of function vs. view? For example, I’d allow a
POST
toapi.profile
for anonymous web users and consider that a sign-up; then an insert trigger would insert a row into the privateauth.user
table. And following the mention here I guess it’s ok to create a new role in the system for every new user sign-up, to implement more fine-grained role-based access control (RBAC).Question 3
As recommended in the OpenAPI section I used
COMMENT
to improve the generated spec. However, I noticed that for the public functions (e.g.api.signup()
above) the spec contains two entries:How can I prevent the
GET
from appearing there and, more generally, how do I control the HTTP methods that are allowed on a function?Question 4
I’ve used pgTAP in the past to test PostgreSQL data modeling and it worked really well. With PostgREST, however, I suppose testing at the HTTP REST API level is more meaningful — what tools do you recommend here? Projects like RESTler Fuzzer seem useful for automation whereas Mocha or pytest require (tedious) manual setup.
What are your recommendations?
Question 5
In other Python projects we always use Alembic to handle db versioning and up/down migrations as the software evolves. There’s an interesting discussion What migration/versioning tool do you use?, discussion #2999, and, in addition, I came across pg_roll. How does PostgREST suggest to evolve the db as the project unfolds?
Question 6
I need to trigger async jobs (Python). There are PostgreSQL extensions that send messages to a queue (e.g. AMQP Bridge) and there’s PG’s own
LISTEN
andNOTIFY
. The naive approach, I guess, would be to set up a Python container that opens a connection & session to the db and then justLISTEN
s endlessly, refreshes the connection periodically, and spawns async workers whenever a notification arrives from the db. (See also dramatiq-pg.)What extensions or suggestions does the community have here?
Beta Was this translation helpful? Give feedback.
All reactions