Compare commits

..

3 Commits

Author SHA1 Message Date
3920183e0c
add address.name kompetenzinventar/ki-doku#8 2021-06-12 12:07:51 +02:00
341521555a
add token table 2021-06-12 12:00:34 +02:00
e905c51625
add production script 2021-06-12 10:06:40 +02:00
6 changed files with 88 additions and 40 deletions

View File

@ -9,6 +9,7 @@ python-dotenv = "*"
flask-migrate = "*" flask-migrate = "*"
flask-sqlalchemy = "*" flask-sqlalchemy = "*"
sqlalchemy = "*" sqlalchemy = "*"
waitress = "*"
[dev-packages] [dev-packages]

72
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "8f1fc0af0f3e270b653aa3cc022a386196cec498776990e08d67f4a751941f53" "sha256": "88e5fb21e69421ebb5788f9c47069d778f9b87246dc340eae094275fb4873d1b"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -211,39 +211,47 @@
}, },
"sqlalchemy": { "sqlalchemy": {
"hashes": [ "hashes": [
"sha256:196fb6bb2733834e506c925d7532f8eabad9d2304deef738a40846e54c31e236", "sha256:0653d444d52f2b9a0cba1ea5cd0fc64e616ee3838ee86c1863781b2a8670fc0c",
"sha256:1dd77acbc19bee9c0ba858ff5e4e5d5c60895495c83b4df9bcdf4ad5e9b74f21", "sha256:146af9e67d0f821b28779d602372e65d019db01532d8f7101e91202d447c14ec",
"sha256:216ff28fe803885ceb5b131dcee6507d28d255808dd5bcffcb3b5fa75be2e102", "sha256:2129d33b54da4d4771868a3639a07f461adc5887dbd9e0a80dbf560272245525",
"sha256:461a4ea803ce0834822f372617a68ac97f9fa1281f2a984624554c651d7c3ae1", "sha256:284b6df04bc30e886998e0fdbd700ef9ffb83bcb484ffc54d4084959240dce91",
"sha256:4b09191ed22af149c07a880f309b7740f3f782ff13325bae5c6168a6aa57e715", "sha256:3690fc0fc671419debdae9b33df1434ac9253155fd76d0f66a01f7b459d56ee6",
"sha256:4c5e20666b33b03bf7f14953f0deb93007bf8c1342e985bd7c7cf25f46fac579", "sha256:3a6afb7a55374329601c8fcad277f0a47793386255764431c8f6a231a6947ee9",
"sha256:4d93b62e98248e3e1ac1e91c2e6ee1e7316f704be1f734338b350b6951e6c175", "sha256:45bbb935b305e381bcb542bf4d952232282ba76881e3458105e4733ba0976060",
"sha256:5732858e56d32fa7e02468f4fd2d8f01ddf709e5b93d035c637762890f8ed8b6", "sha256:495cce8174c670f1d885e2259d710b0120888db2169ea14fc32d1f72e7950642",
"sha256:58c02d1771bb0e61bc9ced8f3b36b5714d9ece8fd4bdbe2a44a892574c3bbc3c", "sha256:4cdc91bb3ee5b10e24ec59303131b791f3f82caa4dd8b36064d1918b0f4d0de4",
"sha256:651cdb3adcee13624ba22d5ff3e96f91e16a115d2ca489ddc16a8e4c217e8509", "sha256:4f375c52fed5f2ecd06be18756f121b3167a1fdc4543d877961fba04b1713214",
"sha256:6fe1c8dc26bc0005439cb78ebc78772a22cccc773f5a0e67cb3002d791f53f0f", "sha256:56958dd833145f1aa75f8987dfe0cf6f149e93aa31967b7004d4eb9cb579fefc",
"sha256:7222f3236c280fab3a2d76f903b493171f0ffc29667538cc388a5d5dd0216a88", "sha256:5b827d3d1d982b38d2bab551edf9893c4734b5db9b852b28d3bc809ea7e179f6",
"sha256:7dc3d3285fb682316d580d84e6e0840fdd8ffdc05cb696db74b9dd746c729908", "sha256:5c62fff70348e3f8e4392540d31f3b8c251dc8eb830173692e5d61896d4309d6",
"sha256:7e45043fe11d503e1c3f9dcf5b42f92d122a814237cd9af68a11dae46ecfcae1", "sha256:5d4b2c23d20acf631456e645227cef014e7f84a111118d530cfa1d6053fd05a9",
"sha256:7eb55d5583076c03aaf1510473fad2a61288490809049cb31028af56af7068ee", "sha256:60cfe1fb59a34569816907cb25bb256c9490824679c46777377bcc01f6813a81",
"sha256:82922a320d38d7d6aa3a8130523ec7e8c70fa95f7ca7d0fd6ec114b626e4b10b", "sha256:664c6cc84a5d2bad2a4a3984d146b6201b850ba0a7125b2fcd29ca06cddac4b1",
"sha256:8e133e2551fa99c75849848a4ac08efb79930561eb629dd7d2dc9b7ee05256e6", "sha256:70674f2ff315a74061da7af1225770578d23f4f6f74dd2e1964493abd8d804bc",
"sha256:949ac299903d2ed8419086f81847381184e2264f3431a33af4679546dcc87f01", "sha256:77549e5ae996de50ad9f69f863c91daf04842b14233e133335b900b152bffb07",
"sha256:a2d225c8863a76d15468896dc5af36f1e196b403eb9c7e0151e77ffab9e7df57", "sha256:8924d552decf1a50d57dca4984ebd0778a55ca2cb1c0ef16df8c1fed405ff290",
"sha256:a5f00a2be7d777119e15ccfb5ba0b2a92e8a193959281089d79821a001095f80", "sha256:93394d68f02ecbf8c0a4355b6452793000ce0ee7aef79d2c85b491da25a88af7",
"sha256:b0ad951a6e590bbcfbfeadc5748ef5ec8ede505a8119a71b235f7481cc08371c", "sha256:9a62b06ad450386a2e671d0bcc5cd430690b77a5cd41c54ede4e4bf46d7a4978",
"sha256:b59b2c0a3b1d93027f6b6b8379a50c354483fe1ebe796c6740e157bb2e06d39a", "sha256:c824d14b52000597dfcced0a4e480fd8664b09fed606e746a2c67fe5fbe8dfd9",
"sha256:bc89e37c359dcd4d75b744e5e81af128ba678aa2ecea4be957e80e6e958a1612", "sha256:cc474d0c40cef94d9b68980155d686d5ad43a9ca0834a8729052d3585f289d57",
"sha256:bde055c019e6e449ebc4ec61abd3e08690abeb028c7ada2a3b95d8e352b7b514", "sha256:d25210f5f1a6b7b6b357d8fa199fc1d5be828c67cc1af517600c02e5b2727e4c",
"sha256:c367ed95d41df584f412a9419b5ece85b0d6c2a08a51ae13ae47ef74ff9a9349", "sha256:d76abceeb6f7c564fdbc304b1ce17ec59664ca7ed0fe6dbc6fc6a960c91370e3",
"sha256:dde05ae0987e43ec84e64d6722ce66305eda2a5e2b7d6fda004b37aabdfbb909", "sha256:e2aa39fdf5bff1c325a8648ac1957a0320c66763a3fa5f0f4a02457b2afcf372",
"sha256:ee6e7ca09ff274c55d19a1e15ee6f884fa0230c0d9b8d22a456e249d08dee5bf", "sha256:eba098a4962e1ab0d446c814ae67e30da82c446b382cf718306cc90d4e2ad85f",
"sha256:f1c68f7bd4a57ffdb85eab489362828dddf6cd565a4c18eda4c446c1d5d3059d", "sha256:ee3428f6100ff2b07e7ecec6357d865a4d604c801760094883587ecdbf8a3533",
"sha256:f63e1f531a8bf52184e2afb53648511f3f8534decb7575b483a583d3cd8d13ed", "sha256:f3357948fa439eb5c7241a8856738605d7ab9d9f276ca5c5cc3220455a5f8e6c",
"sha256:fdad4a33140b77df61d456922b7974c1f1bb2c35238f6809f078003a620c4734" "sha256:ffb18eb56546aa66640fef831e5d0fe1a8dfbf11cdf5b00803826a01dbbbf3b1"
], ],
"index": "pypi", "index": "pypi",
"version": "==1.4.17" "version": "==1.4.18"
},
"waitress": {
"hashes": [
"sha256:29af5a53e9fb4e158f525367678b50053808ca6c21ba585754c77d790008c746",
"sha256:69e1f242c7f80273490d3403c3976f3ac3b26e289856936d1f620ed48f321897"
],
"index": "pypi",
"version": "==2.0.0"
}, },
"werkzeug": { "werkzeug": {
"hashes": [ "hashes": [

View File

@ -1,4 +1,4 @@
# Kompetenzinventar Backend # Kompetenzinventar Backend
## Entwicklung ## Entwicklung
@ -20,6 +20,12 @@ flask run
http://localhost:5000/ http://localhost:5000/
### Produktionsumgebung
Für die Produktionsumgebung wird [waitress](https://docs.pylonsproject.org/projects/waitress/en/latest/) benutzt.
[`run_prod.py`](./run_prod.py) führt die DB Migrationen aus und startet den Server.
### Quellen ### Quellen
* [`./data/iso_639_1.csv`](https://de.wikipedia.org/wiki/Liste_der_ISO-639-1-Codes) * [`./data/iso_639_1.csv`](https://de.wikipedia.org/wiki/Liste_der_ISO-639-1-Codes)

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"
@ -45,6 +57,7 @@ class Address(db.Model):
__tablename__ = "address" __tablename__ = "address"
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
name = Column(String(25), default="")
street = Column(String(25), default="") street = Column(String(25), default="")
house_number = Column(String(10), default="") house_number = Column(String(10), default="")
additional = Column(String(25), default="") additional = Column(String(25), default="")
@ -73,7 +86,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 +109,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: 47ba0a9cf065
Revises: Revises:
Create Date: 2021-06-12 09:45:28.376639 Create Date: 2021-06-12 12:06:29.946450
""" """
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 = '47ba0a9cf065'
down_revision = None down_revision = None
branch_labels = None branch_labels = None
depends_on = None depends_on = None
@ -42,11 +42,13 @@ 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')
) )
op.create_table('address', op.create_table('address',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=25), nullable=True),
sa.Column('street', sa.String(length=25), nullable=True), sa.Column('street', sa.String(length=25), nullable=True),
sa.Column('house_number', sa.String(length=10), nullable=True), sa.Column('house_number', sa.String(length=10), nullable=True),
sa.Column('additional', sa.String(length=25), nullable=True), sa.Column('additional', sa.String(length=25), nullable=True),
@ -66,10 +68,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 +86,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 +98,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')

10
run_prod.py Normal file
View File

@ -0,0 +1,10 @@
from alembic import command
from waitress import serve
from app import app, migrate
with app.app_context():
config = migrate.get_config()
command.upgrade(config, "head")
serve(app, host="0.0.0.0", port=5000)