From 44c34e5785b794de7b6f18bc2a6bd05149eca757 Mon Sep 17 00:00:00 2001 From: rr- Date: Mon, 28 Mar 2016 10:24:53 +0200 Subject: [PATCH] back/users: make user names unique --- ...c2c9_add_unique_constraint_to_user_name.py | 20 +++++++++++++++++++ szurubooru/model/user.py | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 szurubooru/migrations/versions/d186d2e9c2c9_add_unique_constraint_to_user_name.py 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 00000000..a04f0198 --- /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 37d3f62d..394de26b 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)