From cac14b4cfb1c82d222a209ab5c2ae75750b1abdf Mon Sep 17 00:00:00 2001 From: scammo Date: Mon, 4 Oct 2021 19:25:24 +0200 Subject: [PATCH] fix migrations issues, richtige variablen bennung --- ki/actions/seed.py | 24 ++++++++++++------------ ki/handlers/update_profile.py | 6 +++--- ki/models.py | 12 ++++++------ ki/test/test_profile_endpoint.py | 15 +++++++++------ migrations/versions/459520b01f34_.py | 19 ++++++++++--------- migrations/versions/99f6b0756445_.py | 24 ------------------------ 6 files changed, 40 insertions(+), 60 deletions(-) delete mode 100644 migrations/versions/99f6b0756445_.py diff --git a/ki/actions/seed.py b/ki/actions/seed.py index fa3e819..17fede2 100644 --- a/ki/actions/seed.py +++ b/ki/actions/seed.py @@ -31,10 +31,10 @@ def seed_user(nickname, skills=[], languages=[], volunteerwork="", - availabilityStatus=False, + availability_status=False, freetext="", - availabilityText="", - availabilityHoursPerWeek=42): + availability_text="", + availability_hours_per_week=42): app.logger.info(f"seeding {nickname} \\o/") user = User(auth_id=nickname) @@ -43,9 +43,9 @@ def seed_user(nickname, profile = Profile(nickname=nickname, pronouns="", volunteerwork=volunteerwork, - availabilityStatus=availabilityStatus, - availabilityText=availabilityText, - availabilityHoursPerWeek=availabilityHoursPerWeek, + availability_status=availability_status, + availability_text=availability_text, + availability_hours_per_week=availability_hours_per_week, freetext=freetext, visible=visible, user=user) @@ -101,9 +101,9 @@ def seed(dev: bool): peters_profile = Profile(nickname="peternichtlustig", pronouns="Herr Dr. Dr.", volunteerwork="Gartenverein", - availabilityStatus=True, - availabilityHoursPerWeek=42, - availabilityText="Immer", + availability_status=True, + availability_hours_per_week=42, + availability_text="Immer", freetext="Ich mag Kaffee", user=peter) db.session.add(peters_profile) @@ -147,9 +147,9 @@ def seed(dev: bool): seed_user("dirtydieter", visible=True, volunteerwork="Müll sammeln", - availabilityStatus=True, - availabilityHoursPerWeek=24, - availabilityText="Nur Nachts!", + availability_status=True, + availability_hours_per_week=24, + availability_text="Nur Nachts!", freetext="1001010010111!!!", skills=[(Skill.skill_id_php, 5)]) diff --git a/ki/handlers/update_profile.py b/ki/handlers/update_profile.py index 3722b94..762935b 100644 --- a/ki/handlers/update_profile.py +++ b/ki/handlers/update_profile.py @@ -135,9 +135,9 @@ def update_profile(user_id: int): profile.pronouns = request.json.get("pronouns", "") profile.volunteerwork = request.json.get("volunteerwork", "") - profile.availabilityStatus = request.json.get("availabilityStatus", False) - profile.availabilityText = request.json.get("availabilityText", "") - profile.availabilityHoursPerWeek = request.json.get("availabilityHoursPerWeek", 0) + profile.availability_status = request.json.get("availability_status", False) + profile.availability_text = request.json.get("availability_text", "") + profile.availability_hours_per_week = request.json.get("availability_hours_per_week", 0) profile.freetext = request.json.get("freetext", "") profile.visible = request.json.get("visible", False) diff --git a/ki/models.py b/ki/models.py index 3206497..1347e8e 100644 --- a/ki/models.py +++ b/ki/models.py @@ -33,9 +33,9 @@ class Profile(db.Model): volunteerwork = Column(String(4000), default="") freetext = Column(String(4000), default="") - availabilityStatus = Column(Boolean, default=False) - availabilityText = Column(String(4000), default="") - availabilityHoursPerWeek = Column(Integer, default=0) + availability_status = Column(Boolean, default=False) + availability_text = Column(String(4000), default="") + availability_hours_per_week = Column(Integer, default=0) visible = Column(Boolean, nullable=False, default=False) created = Column(DateTime, nullable=False, default=datetime.now) @@ -54,9 +54,9 @@ class Profile(db.Model): "nickname": self.nickname, "pronouns": self.pronouns, "volunteerwork": self.volunteerwork, - "availabilityStatus": self.availabilityStatus, - "availabilityText": self.availabilityText, - "availabilityHoursPerWeek": self.availabilityHoursPerWeek, + "availability_status": self.availability_status, + "availability_text": self.availability_text, + "availability_hours_per_week": self.availability_hours_per_week, "freetext": self.freetext, "visible": self.visible, "address": self.address.to_dict() if self.address else None, diff --git a/ki/test/test_profile_endpoint.py b/ki/test/test_profile_endpoint.py index 698b5d3..af51a5d 100644 --- a/ki/test/test_profile_endpoint.py +++ b/ki/test/test_profile_endpoint.py @@ -33,8 +33,9 @@ class TestProfileEndpoint(ApiTest): data = { "pronouns": "Monsieur", "volunteerwork": "ja", - "availabilityStatus": False, - "availabilityText": "Nie", + "availability_status": False, + "availability_text": "Nie", + "availability_hours_per_week": "23", "freetext": "Hallo", "visible": True, "address": { @@ -111,7 +112,9 @@ class TestProfileEndpoint(ApiTest): profile = user.profile self.assertEqual("Monsieur", profile.pronouns) self.assertEqual("ja", profile.volunteerwork) - self.assertEqual("Nie", profile.availabilityText) + self.assertEqual(False, profile.availability_status) + self.assertEqual("Nie", profile.availability_text) + self.assertEqual(23, profile.availability_hours_per_week) self.assertEqual("Hallo", profile.freetext) self.assertTrue(profile.visible) @@ -199,9 +202,9 @@ class TestProfileEndpoint(ApiTest): "user_id": 1, "nickname": "peternichtlustig", "pronouns": "Herr Dr. Dr.", - "availabilityStatus": True, - "availabilityHoursPerWeek": 25, - "availabilityText": "Immer", + "availability_status": True, + "availability_hours_per_week": 42, + "availability_text": "Immer", "freetext": "Ich mag Kaffee", "volunteerwork": "Gartenverein", "visible": False, diff --git a/migrations/versions/459520b01f34_.py b/migrations/versions/459520b01f34_.py index bdd5e78..75bf85b 100644 --- a/migrations/versions/459520b01f34_.py +++ b/migrations/versions/459520b01f34_.py @@ -11,24 +11,25 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '459520b01f34' -down_revision = '99f6b0756445' +down_revision = '9183e2335b05' branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('profile', sa.Column('availabilityStatus', sa.Boolean(), nullable=True)) - op.add_column('profile', sa.Column('availabilityText', sa.String(length=4000), nullable=True)) - op.add_column('profile', sa.Column('availabilityHoursPerWeek', sa.Integer(), nullable=True)) - op.drop_column('profile', 'availability') + with op.batch_alter_table("profile") as batch_op: + batch_op.add_column(sa.Column('availability_status', sa.Boolean(), nullable=False)) + batch_op.add_column(sa.Column('availability_text', sa.String(length=4000), nullable=True)) + batch_op.add_column(sa.Column('availability_hours_per_week', sa.Integer(), nullable=True)) + batch_op.drop_column('availability') # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.add_column('profile', sa.Column('availability', sa.VARCHAR(length=4000), nullable=True)) - op.drop_column('profile', 'availabilityHoursPerWeek') - op.drop_column('profile', 'availabilityText') - op.drop_column('profile', 'availabilityStatus') + with op.batch_alter_table("profile") as batch_op: + batch_op.drop_column('profile', 'availability_hours_per_week') + batch_op.drop_column('profile', 'availability_text') + batch_op.drop_column('profile', 'availability_status') # ### end Alembic commands ### diff --git a/migrations/versions/99f6b0756445_.py b/migrations/versions/99f6b0756445_.py deleted file mode 100644 index 8544e8f..0000000 --- a/migrations/versions/99f6b0756445_.py +++ /dev/null @@ -1,24 +0,0 @@ -"""empty message - -Revision ID: 99f6b0756445 -Revises: 9183e2335b05 -Create Date: 2021-10-03 14:45:10.980556 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '99f6b0756445' -down_revision = '9183e2335b05' -branch_labels = None -depends_on = None - - -def upgrade(): - pass - - -def downgrade(): - pass