~fnux/meta.sr.ht

3a5042576b1773fecf22c078f6076fc83763fa8e — Drew DeVault 4 months ago e52c3a8 0.51.2
Add unique constraint to user_auth_factor
A metasrht/alembic/versions/2d417400aa37_add_unique_constraint_to_user_auth_.py => metasrht/alembic/versions/2d417400aa37_add_unique_constraint_to_user_auth_.py +23 -0
@@ 0,0 1,23 @@
"""Add unique constraint to user_auth_factor

Revision ID: 2d417400aa37
Revises: 0972ddb8d4f8
Create Date: 2020-10-05 14:17:00.638364

"""

# revision identifiers, used by Alembic.
revision = '2d417400aa37'
down_revision = '0972ddb8d4f8'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.create_unique_constraint('uq_user_auth_factor_user_id',
            'user_auth_factor', ['user_id'])


def downgrade():
    op.drop_constraint('uq_user_auth_factor_user_id', 'user_auth_factor')

M metasrht/types/factors.py => metasrht/types/factors.py +1 -1
@@ 11,7 11,7 @@ class FactorType(Enum):
class UserAuthFactor(Base):
    __tablename__ = 'user_auth_factor'
    id = sa.Column(sa.Integer, primary_key=True)
    user_id = sa.Column(sa.Integer, sa.ForeignKey("user.id"))
    user_id = sa.Column(sa.Integer, sa.ForeignKey("user.id"), unique=True)
    user = sa.orm.relationship('User', backref=sa.orm.backref('auth_factors'))
    created = sa.Column(sa.DateTime, nullable=False)
    updated = sa.Column(sa.DateTime, nullable=False)