Ask HN: Manage DB schema

1 points by blawa ↗ HN
How do you guys manage your DB tables/schemas?

One option is to have an sql script to create the empty tables, and also to start with hardcoded options. (Say all locations, or profession types). During upgrade, you know whats in there and whats not, so on the server, run an sql script that adds columns and any new data.

Another is to do this programmatically, where everytime the server runs- it checks if the db exists, and if not, create it. And during addition of new columns- there would be code that would check if a certain column exists in this schema, and if not add it with a default value of my choice, and also any new data that should be needed.

I'm doing it the former way- but don't feel comfortable because this is risk prone and requires manual care. I can't blindly restore from a backup.

What are the best practices here? For posterity- it would be great if you could specify your - framework, db name and optionally what is your reasoning behind the best practice including the source of any information.

PS: Reddit style comments discouraged- please answer only if you know what you're doing. No offense.

0 comments

[ 3.3 ms ] story [ 7.3 ms ] thread

No comments yet.