schema-tool icon indicating copy to clipboard operation
schema-tool copied to clipboard

Docs: Postgres DB best practices

Open chrisdopuch opened this issue 7 years ago • 1 comments

We are using the schema tool to manage our Postgres DB schema at AppNexus for the AppNexus Exchange API. We ran into a slight issue because the way we set up our initial alters would CREATE DATABASE on the new DB we were creating (sadly Postrgres has no concept of IF NOT EXISTS for DB creation). For Postgres, schema init tries to connect to the DB you have listed in your config.json, and it fails if it can't connect. In the end we decided to remove the CREATE and DROP DB commands from the up/down files to make working with schema tool easier. This means that the DBAs must be informed to create your DB before running your initial alter in prod.

If this idea sounds alright, I would like to contribute a small update to the Readme for schema tool to advise users not to create / drop their DB in their initial alter for Postgres. Basically just some simple best practices to prevent users from shooting themselves in the foot like we did.

You can see the accompanying change I made to the DBA documentation here under NOTE: if using PostgreSQL: https://corpwiki.appnexus.com/display/engineering/How+to+Make+Database+Changes+as+a+Developer

Long term, it might make sense to either have schema tool not error out on init if it can't connect to the DB, or else maybe have it create that DB if it doesn't exist. I'm not sure what implications that would have for the code though.

chrisdopuch avatar Mar 29 '17 23:03 chrisdopuch

Hey @chrisdopuch. Yeah, I know this is a current limitation of the tool. Feel free to open a PR to update the readme.

JohnMurray avatar Mar 30 '17 22:03 JohnMurray