puppetlabs/puppetdb — pull request #375 by cprice-puppet (2012-12-11 02:00:17+00:00)
Title: Bug/master/migrations across branches

commit 0224ccb9444431b539efd5a834e1c4db169723ec
Author: Chris Price
Date: Mon Dec 10 17:48:23 2012 -0800

Slight rework to migration logic

Prior to this commit, we determined whether or not we had outstanding
database migrations to apply by using a simple

`current_schema_version > latest_defined_schema_version`

test. However, this made it impossible to apply bugfix schema changes
to old branches; doing so would prevent the new schema changes in the
current branch from being applied properly when the user upgraded.

This commit changes the logic so that, when determining the list of
outstanding migrations we do a set difference between all of the
defined migrations and all of the applied migrations (which we can
determine by reading from the schema_migrations table in an existing
database). We then attempt to apply all of the pending migrations
in order.

This will allow us, in the hopefully rare cases where it is necessary,
to add a bugfix migration to an old branch as long as we:

1. Make sure that we assign it the next available integer from the
*master* branch (which will leave a gap in the integers in the old
branch), and
2. Make sure that the migration in question can actually be safely
applied either before *or* after the newer migrations in the master
branch.

For clean installs of the master branch, the change will be
last; however, for users who upgrade to a new release off of
the old branch, they'll get the single bugfix migration at that time.
When they upgrade to a release from the new branch, the missing
migrations from the new branch will be applied.

commit 4b3f6f3c35ab42c4740281d148dbbcbb11e6a938
Author: Chris Price
Date: Mon Dec 10 15:41:21 2012 -0800

Add "applied-migrations" function

This commit adds a function 'applied-migrations', which returns
a list of all of the migration versions that have been applied
to the existing database. The idea is that we will use this
to replace the "schema-version" function, so that migrations
will run *all* missing migrations in order, rather than just
checking for the latest numeric value.