Skip to content

Commit

Permalink
Merge pull request #5387 from hypothesis/migration-group-identifier
Browse files Browse the repository at this point in the history
Migration to create group `authority_provided_id` field, index
  • Loading branch information
lyzadanger committed Oct 18, 2018
2 parents b3b814f + 6cfb118 commit 5fbea16
Showing 1 changed file with 43 additions and 0 deletions.
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')

0 comments on commit 5fbea16

Please sign in to comment.