From b536043940bae865b7a7b1c2afca9c26c6d89889 Mon Sep 17 00:00:00 2001 From: Grigoriev Semyon <33061489+semen603089@users.noreply.github.com> Date: Tue, 8 Nov 2022 16:42:00 +0300 Subject: [PATCH] Spec added + migrations (#12) --- design_bot/models/db.py | 2 ++ migrations/versions/c54ae0974f75_spec_add.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 migrations/versions/c54ae0974f75_spec_add.py diff --git a/design_bot/models/db.py b/design_bot/models/db.py index fb9a445..56dad54 100644 --- a/design_bot/models/db.py +++ b/design_bot/models/db.py @@ -18,6 +18,8 @@ class Year(str, Enum): FOURTH = "4" FIFTH = "1м" SIXTH = "2м" + FIFTH_SPEC = "5" + SIXTH_SPEC = "6" class Directions(str, Enum): diff --git a/migrations/versions/c54ae0974f75_spec_add.py b/migrations/versions/c54ae0974f75_spec_add.py new file mode 100644 index 0000000..169a002 --- /dev/null +++ b/migrations/versions/c54ae0974f75_spec_add.py @@ -0,0 +1,18 @@ +from alembic import op +import sqlalchemy as sa + + +revision = 'c54ae0974f75' +down_revision = 'd124a172c3b3' +branch_labels = None +depends_on = None + + +def upgrade(): + op.execute('ALTER TABLE "user" ALTER COLUMN year TYPE varchar(10) USING year::varchar(6);') + + +def downgrade(): + op.execute('DELETE FROM "response" WHERE user_id IN (SELECT id FROM "user" WHERE LENGTH(year) > 6) RETURNING *') + op.execute('DELETE FROM "user" WHERE LENGTH(year) > 6') + op.execute('ALTER TABLE "user" ALTER COLUMN year TYPE varchar(6) USING year::varchar(10);')