Ecto read-only mode, recommendations?

Hello,
Do you guys and girls have recommendations on how do you make a project with Ecto schema modules where you are not allowed to neither change the schema nor any data?

So far the only thing I could think of was to simply delete all changeset() functions that were generated by mix ecto.gen.schema.

I am using MyXQL and I couldn’t find anything related to setting up a Repo in a read-only mode. Same for Postgrex. Both had small disclaimers about a connection temporarily becoming read-only and that this can be worked around by making the driver reconnect in this case – but nothing more.

Does a read-only concept exist in Ecto?

This doesn’t really answer your question about Ecto, but would it be an option for your use case to setup a read-only postgres user and then use that for a separate read-only repo?

2 Likes

Good idea. If nobody else chimes in, I’ll likely resort to making a second user (I use MySQL though) that has no insert/update/delete privileges and just use that one.

Seems like I messed up my search inside Ecto’s hexdocs earlier. After a second try, yes, of course you can mark a Repo as being read-only:

https://hexdocs.pm/ecto/Ecto.Repo.html#module-read-only-repositories

5 Likes

…but you can’t make a singular schema read-only. Simply not having changeset function(s) in the module is a good hint that this schema is not meant to be changed. Good enough.

4 Likes