add rest of the models

This commit is contained in:
weeman 2021-06-07 17:26:07 +02:00
parent 077c16fc2b
commit 802f227676
Signed by untrusted user: weeman
GPG Key ID: 34F0524D4DA694A1
2 changed files with 64 additions and 4 deletions

View File

@ -1,3 +1,5 @@
from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Table
from sqlalchemy.orm import relationship
@ -7,6 +9,11 @@ user_skill_table = Table("user_skill", db.Model.metadata,
Column("user_id", Integer, ForeignKey("user.id")),
Column("skill_id", Integer, ForeignKey("skill.id")))
user_language_table = Table(
"user_language", db.Model.metadata,
Column("user_id", Integer, ForeignKey("user.id")),
Column("language_id", Integer, ForeignKey("language.id")))
class User(db.Model):
__tablename__ = "user"
@ -16,11 +23,35 @@ class User(db.Model):
pronouns = Column(String(25), default="")
volunteerwork = Column(String(4000), default="")
freetext = Column(String(4000), default="")
created = Column(DateTime, nullable=False)
updated = Column(DateTime, onupdate=datetime.now, nullable=False)
relationship("Address", uselist=False, back_populates="user")
contacts = relationship("Contact")
address = relationship("Address", uselist=False, back_populates="user")
skills = relationship("Skill",
secondary=user_skill_table,
back_populates="users")
languages = relationship("Language",
secondary=user_language_table,
back_populates="users")
class Contact(db.Model):
__tablename__ = "contact"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("user.id"))
user = relationship("User", back_populates="contacts")
contacttype_id = Column(Integer, ForeignKey("contacttype.id"))
contacttype = relationship("ContactType")
content = Column(String(200), nullable=False)
class ContactType(db.Model):
__tablename__ = "contacttype"
id = Column(Integer, primary_key=True)
name = Column(String(25), nullable=False)
class Address(db.Model):
@ -54,3 +85,7 @@ class Language(db.Model):
id = Column(Integer, primary_key=True)
name = Column(String(25), nullable=False)
users = relationship("User",
secondary=user_language_table,
back_populates="languages")

View File

@ -1,8 +1,8 @@
"""Initial migration
Revision ID: 409bf7623e6c
Revision ID: 4ff86e9f6a43
Revises:
Create Date: 2021-06-05 21:59:31.863399
Create Date: 2021-06-07 17:25:08.792899
"""
from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '409bf7623e6c'
revision = '4ff86e9f6a43'
down_revision = None
branch_labels = None
depends_on = None
@ -18,6 +18,11 @@ depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('contacttype',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=25), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('language',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=25), nullable=False),
@ -35,6 +40,8 @@ def upgrade():
sa.Column('pronouns', sa.String(length=25), nullable=True),
sa.Column('volunteerwork', sa.String(length=4000), nullable=True),
sa.Column('freetext', sa.String(length=4000), nullable=True),
sa.Column('created', sa.DateTime(), nullable=False),
sa.Column('updated', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('nickname')
)
@ -50,6 +57,21 @@ def upgrade():
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('contact',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('contacttype_id', sa.Integer(), nullable=True),
sa.Column('content', sa.String(length=200), nullable=False),
sa.ForeignKeyConstraint(['contacttype_id'], ['contacttype.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user_language',
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('language_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['language_id'], ['language.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], )
)
op.create_table('user_skill',
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('skill_id', sa.Integer(), nullable=True),
@ -62,8 +84,11 @@ def upgrade():
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user_skill')
op.drop_table('user_language')
op.drop_table('contact')
op.drop_table('address')
op.drop_table('user')
op.drop_table('skill')
op.drop_table('language')
op.drop_table('contacttype')
# ### end Alembic commands ###