Skip to content

Commit

Permalink
fixes (#116)
Browse files Browse the repository at this point in the history
Co-authored-by: Парфенов Михаил Александрович <[email protected]>
  • Loading branch information
parfenovma and Парфенов Михаил Александрович authored Dec 12, 2024
1 parent 3df7c6e commit 41d6a76
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
56 changes: 56 additions & 0 deletions migrations/versions/20241212_1543_f62898bb3315_uids_to_dims.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""uids_to_dims
Revision ID: f62898bb3315
Revises: 0d462525c992
Create Date: 2024-12-12 15:43:14.642986
"""

from alembic import op
import sqlalchemy as sa
import os


# revision identifiers, used by Alembic.
revision = 'f62898bb3315'
down_revision = '0d462525c992'
branch_labels = None
depends_on = None


def upgrade():
# alembic cannot do it properly, so you need to manually handle columns
# dim_event_act
op.execute('ALTER TABLE "DM_TIMETABLE".dim_event_act drop COLUMN IF EXISTS id')
op.execute('ALTER TABLE "DM_TIMETABLE".dim_event_act add COLUMN IF not EXISTS id UUID')
# dim_group_act
op.execute('ALTER TABLE "DM_TIMETABLE".dim_group_act drop COLUMN IF EXISTS id')
op.execute('ALTER TABLE "DM_TIMETABLE".dim_group_act add COLUMN IF not EXISTS id UUID')
# dim_lecturer_act
op.execute('ALTER TABLE "DM_TIMETABLE".dim_lecturer_act drop COLUMN IF EXISTS id')
op.execute('ALTER TABLE "DM_TIMETABLE".dim_lecturer_act add COLUMN IF not EXISTS id UUID')
# dim_room_act
op.execute('ALTER TABLE "DM_TIMETABLE".dim_room_act drop COLUMN IF EXISTS id')
op.execute('ALTER TABLE "DM_TIMETABLE".dim_room_act add COLUMN IF not EXISTS id UUID')
op.drop_column('ods_link_timetable_group', 'lesson_id', schema='ODS_TIMETABLE')


def downgrade():
op.add_column(
'ods_link_timetable_group',
sa.Column('lesson_id', sa.INTEGER(), autoincrement=False, nullable=True),
schema='ODS_TIMETABLE',
)
# alembic cannot do it properly, so you need to manually handle columns
# dim_event_act
op.execute('ALTER TABLE "DM_TIMETABLE".dim_event_act drop COLUMN IF EXISTS id')
op.execute('ALTER TABLE "DM_TIMETABLE".dim_event_act add COLUMN IF not EXISTS id INTEGER')
# dim_group_act
op.execute('ALTER TABLE "DM_TIMETABLE".dim_group_act drop COLUMN IF EXISTS id')
op.execute('ALTER TABLE "DM_TIMETABLE".dim_group_act add COLUMN IF not EXISTS id INTEGER')
# dim_lecturer_act
op.execute('ALTER TABLE "DM_TIMETABLE".dim_lecturer_act drop COLUMN IF EXISTS id')
op.execute('ALTER TABLE "DM_TIMETABLE".dim_lecturer_act add COLUMN IF not EXISTS id INTEGER')
# dim_room_act
op.execute('ALTER TABLE "DM_TIMETABLE".dim_room_act drop COLUMN IF EXISTS id')
op.execute('ALTER TABLE "DM_TIMETABLE".dim_room_act add COLUMN IF not EXISTS id INTEGER')
12 changes: 8 additions & 4 deletions profcomff_definitions/DM/timetable.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

import uuid

from sqlalchemy import UUID, String
from sqlalchemy.orm import Mapped, mapped_column

from profcomff_definitions.base import Base


class DimRoomAct(Base):
id: Mapped[int] = mapped_column(primary_key=True)
id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4)
room_api_id: Mapped[int]
room_name: Mapped[str | None]
room_direction_text_type: Mapped[str | None]
Expand All @@ -13,7 +17,7 @@ class DimRoomAct(Base):


class DimLecturerAct(Base):
id: Mapped[int] = mapped_column(primary_key=True)
id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4)
lecturer_api_id: Mapped[int]
lecturer_first_name: Mapped[str | None]
lecturer_middle_name: Mapped[str | None]
Expand All @@ -24,15 +28,15 @@ class DimLecturerAct(Base):


class DimGroupAct(Base):
id: Mapped[int] = mapped_column(primary_key=True)
id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4)
group_api_id: Mapped[int]
group_name_text: Mapped[str | None]
group_number: Mapped[str | None]
source_name: Mapped[str]


class DimEventAct(Base):
id: Mapped[int] = mapped_column(primary_key=True)
id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4)
event_api_id: Mapped[int | None]
event_name_text: Mapped[str | None]
source_name: Mapped[str]

0 comments on commit 41d6a76

Please sign in to comment.