pull-requests.md
February 21, 2019 ยท View on GitHub
Pull Request Review and Merging
In the below scenario, we will keep a consistent naming scheme: branches will have any type (e.g. feat/) removed, then the whole thing will be converted to snake_case and prefixed with app_.
-
Imagine you're working on a new feature branch
feat/shiny-new, and that feature includes some new database migrations. -
While you're working, your co-worker has an urgent request: she needs her
fix/urgentbranch reviewed ASAP! -
Because you're already using
pgsh, your feature databaseapp_shiny_newis separate from yourdevelopbranch databaseapp_develop. Switch back to it usingpgsh switch app_develop, as it is a common ancestor for your and your co-worker's development history. -
Let's
git pullthengit checkout fix/urgent. -
Turns out that as part of the fix for the bug, your co-worker needed to retroactively fix some entries in the database, resulting in a new migration,
050_fix_timestamps.js. Let's clone our database so we can try out the migration without clobbering our data:pgsh clone app_urgent. -
pgsh upwill migrate the newly-created database up to version 50. -
You can now explore the applied database and run the branch's code against it, verifying both the code fix and that the migration also works with your local data.
-
Let's say you approve the pull request and merge into
develop. While the ops team is busy deploying the fix, we can move our migrations around so that come PR time things aren't so difficult. -
Pull the
developbranch changes bygit checkout develop && git pull. -
Switch back to our branch by
git checkout feat/shiny_new && pgsh switch app_shiny_new. -
Let's bring our co-worker's changes and migrations into our branch:
git merge developorgit rebase develop, depending on your workflow. -
Because migrations are ordered, we now have two
050_migrations. Our co-worker's code has been committed todevelop, so we need to re-order our migrations after by increasing their sequence number(s). -
Now we have a valid migrations directory, but our knex migration log doesn't know about our co-worker's migration (and it hasn't been applied to our database). Let's fix the latter first by manually running the migration code by pasting it into
pgsh psql, preferably inside of a transaction so we can rollback if we get into trouble.- in the future, pgsh will facilitate this more directly.
-
If there are problems, we should fix them in our migration(s).
-
Once you've manually migrated the database to the latest version, run
pgsh force-upto re-write theknex_migrationstable and complete your process.