add token table

This commit is contained in:
weeman 2021-06-12 12:00:34 +02:00
parent e905c51625
commit 341521555a
Signed by: weeman
GPG Key ID: 34F0524D4DA694A1
2 changed files with 28 additions and 7 deletions

View File

@ -16,13 +16,25 @@ class User(db.Model):
freetext = Column(String(4000), default="") freetext = Column(String(4000), default="")
created = Column(DateTime, nullable=False) created = Column(DateTime, nullable=False)
updated = Column(DateTime, onupdate=datetime.now, nullable=False) updated = Column(DateTime, onupdate=datetime.now, nullable=False)
auth_id = Column(String(50), nullable=False)
contacts = relationship("Contact") contacts = relationship("Contact")
address = relationship("Address", uselist=False, back_populates="user") address = relationship("Address", uselist=False, back_populates="user")
tokens = relationship("Token", uselist=False, back_populates="user")
skills = relationship("UserSkill", back_populates="users") skills = relationship("UserSkill", back_populates="users")
languages = relationship("UserLanguage", "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): class Contact(db.Model):
__tablename__ = "contact" __tablename__ = "contact"
@ -73,7 +85,7 @@ class UserSkill(db.Model):
user_id = Column(Integer, ForeignKey("user.id"), primary_key=True) user_id = Column(Integer, ForeignKey("user.id"), primary_key=True)
skill_id = Column(Integer, ForeignKey("skill.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") user = relationship("User", back_populates="skills")
skill = relationship("Skill", back_populates="users") skill = relationship("Skill", back_populates="users")
@ -96,7 +108,7 @@ class UserLanguage(db.Model):
user_id = Column(Integer, ForeignKey("user.id"), primary_key=True) user_id = Column(Integer, ForeignKey("user.id"), primary_key=True)
language_id = Column(Integer, ForeignKey("language.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") user = relationship("User", back_populates="languages")
language = relationship("Language", back_populates="users") language = relationship("Language", back_populates="users")

View File

@ -1,8 +1,8 @@
"""Initial migration """Initial migration
Revision ID: aebc7e73ad96 Revision ID: 3dfe40b821a5
Revises: Revises:
Create Date: 2021-06-12 09:45:28.376639 Create Date: 2021-06-12 11:58:43.577221
""" """
from alembic import op from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'aebc7e73ad96' revision = '3dfe40b821a5'
down_revision = None down_revision = None
branch_labels = None branch_labels = None
depends_on = None depends_on = None
@ -42,6 +42,7 @@ def upgrade():
sa.Column('freetext', sa.String(length=4000), nullable=True), sa.Column('freetext', sa.String(length=4000), nullable=True),
sa.Column('created', sa.DateTime(), nullable=False), sa.Column('created', sa.DateTime(), nullable=False),
sa.Column('updated', 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.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('nickname') sa.UniqueConstraint('nickname')
) )
@ -66,10 +67,17 @@ def upgrade():
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('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', op.create_table('user_language',
sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('language_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(['language_id'], ['language.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('user_id', 'language_id') sa.PrimaryKeyConstraint('user_id', 'language_id')
@ -77,7 +85,7 @@ def upgrade():
op.create_table('user_skill', op.create_table('user_skill',
sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('skill_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(['skill_id'], ['skill.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('user_id', 'skill_id') sa.PrimaryKeyConstraint('user_id', 'skill_id')
@ -89,6 +97,7 @@ def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user_skill') op.drop_table('user_skill')
op.drop_table('user_language') op.drop_table('user_language')
op.drop_table('token')
op.drop_table('contact') op.drop_table('contact')
op.drop_table('address') op.drop_table('address')
op.drop_table('user') op.drop_table('user')