diff --git a/szurubooru/migrations/versions/d186d2e9c2c9_add_unique_constraint_to_user_name.py b/szurubooru/migrations/versions/d186d2e9c2c9_add_unique_constraint_to_user_name.py new file mode 100644 index 0000000..a04f019 --- /dev/null +++ b/szurubooru/migrations/versions/d186d2e9c2c9_add_unique_constraint_to_user_name.py @@ -0,0 +1,20 @@ +''' +Add unique constraint to the user name + +Revision ID: d186d2e9c2c9 +Created at: 2016-03-28 10:21:30.440333 +''' + +import sqlalchemy as sa +from alembic import op + +revision = 'd186d2e9c2c9' +down_revision = 'e5c1216a8503' +branch_labels = None +depends_on = None + +def upgrade(): + op.create_unique_constraint('uq_user_name', 'user', ['name']) + +def downgrade(): + op.drop_constraint('uq_user_name', 'user', type_='unique') diff --git a/szurubooru/model/user.py b/szurubooru/model/user.py index 37d3f62..394de26 100644 --- a/szurubooru/model/user.py +++ b/szurubooru/model/user.py @@ -5,7 +5,7 @@ class User(Base): __tablename__ = 'user' user_id = sa.Column('id', sa.Integer, primary_key=True) - name = sa.Column('name', sa.String(50), nullable=False) + name = sa.Column('name', sa.String(50), nullable=False, unique=True) password_hash = sa.Column('password_hash', sa.String(64), nullable=False) password_salt = sa.Column('pasword_salt', sa.String(32)) email = sa.Column('email', sa.String(200), nullable=True)