From 341521555acf5dc7da76cf42702ede8a7a6ba839 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Sat, 12 Jun 2021 12:00:34 +0200 Subject: [PATCH] add token table --- ki/models.py | 16 ++++++++++++++-- ...n.py => 3dfe40b821a5_initial_migration.py} | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) rename migrations/versions/{aebc7e73ad96_initial_migration.py => 3dfe40b821a5_initial_migration.py} (85%) diff --git a/ki/models.py b/ki/models.py index 231f0b1..fec1b46 100644 --- a/ki/models.py +++ b/ki/models.py @@ -16,13 +16,25 @@ class User(db.Model): freetext = Column(String(4000), default="") created = Column(DateTime, nullable=False) updated = Column(DateTime, onupdate=datetime.now, nullable=False) + auth_id = Column(String(50), nullable=False) contacts = relationship("Contact") address = relationship("Address", uselist=False, back_populates="user") + tokens = relationship("Token", uselist=False, back_populates="user") skills = relationship("UserSkill", back_populates="users") languages = relationship("UserLanguage", "users") +class Token(db.Model): + __tablename__ = "token" + + id = Column(Integer, primary_key=True) + user_id = Column(Integer, ForeignKey("user.id")) + token = Column(String(36), nullable=False) + + user = relationship("User", back_populates="tokens") + + class Contact(db.Model): __tablename__ = "contact" @@ -73,7 +85,7 @@ class UserSkill(db.Model): user_id = Column(Integer, ForeignKey("user.id"), primary_key=True) skill_id = Column(Integer, ForeignKey("skill.id"), primary_key=True) - level = Column(SmallInteger) + level = Column(SmallInteger, nullable=False) user = relationship("User", back_populates="skills") skill = relationship("Skill", back_populates="users") @@ -96,7 +108,7 @@ class UserLanguage(db.Model): user_id = Column(Integer, ForeignKey("user.id"), primary_key=True) language_id = Column(Integer, ForeignKey("language.id"), primary_key=True) - level = Column(SmallInteger) + level = Column(SmallInteger, nullable=False) user = relationship("User", back_populates="languages") language = relationship("Language", back_populates="users") diff --git a/migrations/versions/aebc7e73ad96_initial_migration.py b/migrations/versions/3dfe40b821a5_initial_migration.py similarity index 85% rename from migrations/versions/aebc7e73ad96_initial_migration.py rename to migrations/versions/3dfe40b821a5_initial_migration.py index 6eed83d..acc287a 100644 --- a/migrations/versions/aebc7e73ad96_initial_migration.py +++ b/migrations/versions/3dfe40b821a5_initial_migration.py @@ -1,8 +1,8 @@ """Initial migration -Revision ID: aebc7e73ad96 +Revision ID: 3dfe40b821a5 Revises: -Create Date: 2021-06-12 09:45:28.376639 +Create Date: 2021-06-12 11:58:43.577221 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = 'aebc7e73ad96' +revision = '3dfe40b821a5' down_revision = None branch_labels = None depends_on = None @@ -42,6 +42,7 @@ def upgrade(): sa.Column('freetext', sa.String(length=4000), nullable=True), sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), + sa.Column('auth_id', sa.String(length=50), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('nickname') ) @@ -66,10 +67,17 @@ def upgrade(): sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) + op.create_table('token', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('token', sa.String(length=36), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_table('user_language', sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('language_id', sa.Integer(), nullable=False), - sa.Column('level', sa.SmallInteger(), nullable=True), + sa.Column('level', sa.SmallInteger(), nullable=False), sa.ForeignKeyConstraint(['language_id'], ['language.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('user_id', 'language_id') @@ -77,7 +85,7 @@ def upgrade(): op.create_table('user_skill', sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('skill_id', sa.Integer(), nullable=False), - sa.Column('level', sa.SmallInteger(), nullable=True), + sa.Column('level', sa.SmallInteger(), nullable=False), sa.ForeignKeyConstraint(['skill_id'], ['skill.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('user_id', 'skill_id') @@ -89,6 +97,7 @@ def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_table('user_skill') op.drop_table('user_language') + op.drop_table('token') op.drop_table('contact') op.drop_table('address') op.drop_table('user')