Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yesod multiple persistent backends for one site

Tags:

haskell

yesod

A common pattern between development and production is a dev website will use sqlite, because it is zero setup, but then use PostgresSQL or MySQL in production. However, in the default Settings.hs scaffolding file generated by Yesod, only one persistent backend is specified. Is there a way to have the Development configuration use one persistent backend, and the Production configuration another? Additionally, these should have distinct database setting YAML files, so that a simple filename can be configured for sqlite, but production db credentials never hit the VCS repository.

like image 279
Edward Z. Yang Avatar asked Nov 12 '22 19:11

Edward Z. Yang


1 Answers

I don't like this practice in general, as there can be subtle differences between database engines that don't show up until production. (This can be mitigated by having a staging server in-between.)

Anyway, you can certainly do this via conditional compilation, though the scaffolded site isn't designed to work that way out-of-the-box. Just look for all the places that refer to a specific backend and make it conditional on the DEVELOPMENT CPP variable.

like image 113
Michael Snoyman Avatar answered Nov 27 '22 02:11

Michael Snoyman