Don't create branch duplicates (#862)
Don't create branch duplicates (#862)

When using `Branch.where().first_or_initialize` concurrently there's a
chance of creating branch duplicates. We can't use a unique index on
(repository_id, name) because there are already duplicates in the
branches table, but this commit uses a slightly different approach. A
`unique_name` column has been added to the database that is
automatically populated on insert and update with a value of `name`. A
partial unique index is also set on `(repository_id, unique_name) WHERE
unique_name IS NOT NULL`. Thanks to that we can use "upser" (ie. `INSERT
... ON CONFLICT`).
travis-ci/travis-api,travis-ci/travis-api,travis-ci/travis-api