From 257fd6a533f24c64113c609b1f9fd9bcdc3add36 Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Sat, 5 Oct 2019 23:57:36 -0700 Subject: [PATCH] add username --- migrations/versions/0e0f8ad1362d_.py | 30 ++++++++++++++++++++++++++++ migrations/versions/9519d28f13f0_.py | 2 +- models/User.py | 10 +++++----- 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 migrations/versions/0e0f8ad1362d_.py diff --git a/migrations/versions/0e0f8ad1362d_.py b/migrations/versions/0e0f8ad1362d_.py new file mode 100644 index 0000000..62a07e0 --- /dev/null +++ b/migrations/versions/0e0f8ad1362d_.py @@ -0,0 +1,30 @@ +"""empty message + +Revision ID: 0e0f8ad1362d +Revises: 50aab465cf44 +Create Date: 2019-10-05 23:21:57.620808 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '0e0f8ad1362d' +down_revision = '50aab465cf44' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('users', sa.Column('username', sa.String(length=255), nullable=False)) + op.create_unique_constraint(None, 'users', ['username']) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'users', type_='unique') + op.drop_column('users', 'username') + # ### end Alembic commands ### diff --git a/migrations/versions/9519d28f13f0_.py b/migrations/versions/9519d28f13f0_.py index 8633673..51b4535 100644 --- a/migrations/versions/9519d28f13f0_.py +++ b/migrations/versions/9519d28f13f0_.py @@ -39,7 +39,7 @@ def upgrade(): op.create_table('users', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('email', sa.String(length=255), nullable=False), - sa.Column('password', sa.Integer(length=255), nullable=False), + sa.Column('password', sa.String(length=255), nullable=False), sa.Column('registered_on', sa.DateTime(), nullable=False), sa.Column('admin', sa.Boolean(), nullable=False), sa.Column('rank', sa.Enum('D7', 'D6', 'D5', 'D4', 'D3', 'D2', 'D1', 'K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9', 'K10', 'K11', 'K12', 'K13', 'K14', 'K15', 'K16', 'K17', 'K18', 'K19', 'K20', 'K21', 'K22', 'K23', 'K24', 'K25', 'K26', 'K27', 'K28', 'K29', 'K30', name='ranks'), nullable=True), diff --git a/models/User.py b/models/User.py index 7fd6fff..33a61d2 100644 --- a/models/User.py +++ b/models/User.py @@ -49,6 +49,7 @@ class User(db.Model): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True, autoincrement=True) + username = db.Column(db.String(255), unique=True, nullable=False, autoincrement=True) email = db.Column(db.String(255), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False) registered_on = db.Column(db.DateTime, nullable=False) @@ -57,14 +58,13 @@ class User(db.Model): elo = db.Column(db.Integer) rank_certainty = db.Column(db.Boolean, nullable=False, default=False) - def __init__(self, email, password, admin=False,): - print('user init') + def __init__(self, username, email, password, rank='RU', admin=False): + self.username = username self.email = email - print('user email init') self.password = bcrypt.generate_password_hash( password, 13 ).decode() - print('user password init') + self.rank = rank self.registered_on = datetime.datetime.now() self.admin = admin @@ -106,7 +106,7 @@ class UserSchema(ma.ModelSchema): class Meta: fields = ( 'id', - 'name', + 'username', 'email', 'registered_on', 'rank',