Closed nurpax closed 12 years ago
Also, need example to show when and how to create tables.
Good suggestion. So far I have used only local scripts for creating tables. I.e., having 01-schema.sql scripts which contain SQL statements for table creation. If the schema changes, one can create 02-schema.sql script that uses ALTERs to change from schema version 1 to 2, and so on. A restart of the Snap server will be required if the schema is modified.
Another approach would be to check database schema version on every query, and calling an upgrade/creation Haskell function to create tables as necessary. However, this has the cost of one extra query per request as one needs to query the database schema version.
Having the table creation & upgrade happen in Haskell code would be preferable from the example's POV. This way anyone who tries to run the example won't need to worry about running separate SQL queries on the command line just to get the example app to run.
@daapp Did you have any suggestions or preferences where and how you might take care of table creation?
@mightybyte Did you ever give this any thought in snaplet-postgresql-simple?
Migrations are tricky. snaplet-postgresql-simple is intended to be a simple wrapper around postgresql-simple, so I'll leave migration features to them.
EDIT: Actually, the new groundhog has some migration support that looks interesting.
@mightybyte Sorry for being vague in my question. I don't actually plan on baking any type of generic migration into snaplet-sqlite-simple (or into sqlite-simple).
I was fishing for tips in case you had an "obvious" place in the snaplet framework to hook stuff like DB table creation into. Now that I'm thinking about this again, perhaps a good place for this type of stuff would be in
-- | The application initializer.
app :: SnapletInit App App
Yes. snaplet-postgresql-simple has this.
@daapp You might find commit d53b8fdcb interesting..
This should be a lot better already in the latest in the snap-0.10 branch. Will be merged to master when snap-0.10 gets released.