killercup / scribbles

Some notes on various topics.
https://deterministic.space
64 stars 11 forks source link

What about migrations? #55

Open kaning opened 1 month ago

kaning commented 1 month ago

I stumbled on your post while researching how to use postgres views with diesel. I had seen this workaround before but this articled helped solidify some things I was thinking about.

What it does not mention though is that if you manager your schema with migrations, Diesel will leave you in the cold, because it only prints-schemas with tables and such... Views will go missing every time diesel regenerates your schema file.

A way to fix that is to use the patch_file config in the diesel.toml... If you create a patch file from the diff of your view in the schema.rs file, it will apply the patch AFTER it generates the schema and you have your views remaining in the schema.rs.

Hopefully this helps someone