diff --git a/migrations/versions/20241212_1543_f62898bb3315_uids_to_dims.py b/migrations/versions/20241212_1543_f62898bb3315_uids_to_dims.py new file mode 100644 index 0000000..324eb61 --- /dev/null +++ b/migrations/versions/20241212_1543_f62898bb3315_uids_to_dims.py @@ -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') \ No newline at end of file diff --git a/profcomff_definitions/DM/timetable.py b/profcomff_definitions/DM/timetable.py index d0ea023..bb020f3 100644 --- a/profcomff_definitions/DM/timetable.py +++ b/profcomff_definitions/DM/timetable.py @@ -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] @@ -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] @@ -24,7 +28,7 @@ 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] @@ -32,7 +36,7 @@ class DimGroupAct(Base): 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]