If you already have a Database and would like to start using codd, here's a guideline to approach the problem. Remember to be very careful if/when making any changes to your Prod DB:
- Configure your environment variables as explained in the README and in CONFIGURATION.md.
- In that configuration make sure you have that extra
dev-onlyfolder to hold SQL migrations that will only run in developers' machines. - Run
pg_dump your_database > dump-migration.sql. Do not usepg_dumpallbecause it includes psql's meta-commands that codd doesn't support. - Run
dropdb your_databaseto drop your DB locally. - Add a bootstrap migration similar to the one exemplified in BOOTSTRAPPING.md, but with ownership, encoding and locale equal to your Production DB's. The database's and the public's Schema ownership might need some manual intervention to match in different environments.
- What do we mean? Cloud services such as Amazon's RDS will create Schemas and DBs owned by users managed by them - such as the
rdsadminuser -, that we don't usually replicate locally. We can either replicate these locally so we don't need to touch our Prod DB or change our Prod DB so only users managed by us are ever referenced in any environment.
- What do we mean? Cloud services such as Amazon's RDS will create Schemas and DBs owned by users managed by them - such as the
- Make sure the bootstrap migrations added in the previous step create the database, roles and ownership match what you get in Production.
- Use psql's
\dgto view roles in your Prod DB. - Use psql's
\lto check DB ownership and permissions of your Prod DB. - Use psql's
\dn+to check the public schema's ownership and permissions in your Prod DB.
- Use psql's
- Edit
dump-migration.sql(created in step 3) and add-- codd: no-txnas its very first line. - Run
codd add dump-migration.sql --dest-folder your-dev-only-folder - You should now have your database back and managed through codd.
- Make sure your Production environment variable
CODD_MIGRATION_DIRSdoes not contain yourdev-onlyfolder. Add any future SQL migrations to yourall-migrationsfolder. - Before deploying with codd, we strongly recommend you run
codd verify-schemawith your environment variables connected to your Production database and make sure schemas match. - In Production, we strongly recommend running
codd up --lax-checkto start with until you get acquainted enough to consider strict-checking. Make sure you readcodd up --helpto better understand your options.