-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5387 from hypothesis/migration-group-identifier
Migration to create group `authority_provided_id` field, index
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
h/migrations/versions/5ed9c8c105f6_add_authority_provided_id_field_to_group.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Add authority_provided_id field, index to group | ||
This will allow clients of the API, in certain circumstances, to set a | ||
unique-to-authority identifier on a group, versus having to use the | ||
service-generated ``pubid``. This ``authority_provided_id`` can be used | ||
to perform certain actions on the group without having to know the | ||
``pubid`` beforehand. | ||
Whereas the ``pubid`` is service-owned and globally unique, this | ||
``authority_provided_id`` is unique per authority and owned by the | ||
caller/client. i.e. authority-bound clients may set their own unique | ||
IDs. | ||
``authority_provided_id`` must be unique per authority; ergo the | ||
unique-enforced index | ||
""" | ||
from __future__ import unicode_literals | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
revision = "5ed9c8c105f6" | ||
down_revision = "5d256923d642" | ||
|
||
|
||
def upgrade(): | ||
op.add_column('group', sa.Column('authority_provided_id', sa.UnicodeText(), nullable=True)) | ||
op.execute('COMMIT') | ||
op.create_index(op.f('ix__group__groupid'), | ||
'group', | ||
['authority', 'authority_provided_id'], | ||
postgresql_concurrently=True, | ||
unique=True) | ||
|
||
|
||
def downgrade(): | ||
op.drop_index(op.f('ix__group__groupid')) | ||
op.drop_column('group', 'authority_provided_id') |