Are there any established practises for how the migration of database views can be successfully handled in a multi-developer / multi-branch (VCS) environment?
We've been using a database migration library for all our schema changes, but have run into problems when different developers in different branches of code alter the same view, but their point of origin was the same.
Each developer has their own copy of the database, but as views typically require the whole definition to be specified in the migration, this means that when we come to run the migrations against the staging or production database, whichever view migration gets run last overwrites any changes made in any previous view migrations.
Example:
- View currently looks like:
SELECT 'x'
. - Developer 1 starts branch A and adds a new column. Their 'up' migration looks like:
SELECT 'x', 'y'
. - Developer 2 starts branch B and adds a new column. Their 'up' migration looks like:
SELECT 'x', 'z'
. - Developer 2 finishes her branch first and runs the migrations. The view now looks like
SELECT 'x', 'z'
. - Developer 1 now finishes his branch and runs the migrations. The view now looks like
SELECT 'x', 'y'
and developer 2's changes have been lost.