diff --git a/migrations/custom_scripts/__init__.py b/migrations/custom_scripts/__init__.py index e52b276d..8a9146da 100644 --- a/migrations/custom_scripts/__init__.py +++ b/migrations/custom_scripts/__init__.py @@ -2,7 +2,6 @@ from .operations_schemas import create_table_schema, drop_table_schema from .render import render_create_group, render_create_sequence, render_drop_group, render_drop_sequence from .schemas import add_table_schema_to_model, compare_schemas -from .tables import compare_table __all__ = [ diff --git a/migrations/custom_scripts/tables.py b/migrations/custom_scripts/tables.py index 26e912f8..fae0aea0 100644 --- a/migrations/custom_scripts/tables.py +++ b/migrations/custom_scripts/tables.py @@ -1,10 +1,7 @@ import os from alembic.autogenerate import comparators -from sqlalchemy import text -from .operations_groups import CreateGroupOp, DeleteGroupOp, GrantOnSchemaOp, RevokeOnSchemaOp -from .operations_schemas import CreateTableSchemaOp, DropTableSchemaOp from .operations_tables import GrantRightsOp, RevokeRightsOp diff --git a/migrations/versions/20240512_0913_7353088d02ce_.py b/migrations/versions/20240512_0913_7353088d02ce_.py index 43c0c31b..2990f85e 100644 --- a/migrations/versions/20240512_0913_7353088d02ce_.py +++ b/migrations/versions/20240512_0913_7353088d02ce_.py @@ -6,12 +6,6 @@ """ -import os - -import sqlalchemy as sa -from alembic import op - - # revision identifiers, used by Alembic. revision = '7353088d02ce' down_revision = ('8b6f4a99f692', 'd80ebb009b4e') diff --git a/migrations/versions/20240818_0818_c1312de67d70_alter_timetable_dim_columns.py b/migrations/versions/20240818_0818_c1312de67d70_alter_timetable_dim_columns.py index bb417f66..79a946b2 100644 --- a/migrations/versions/20240818_0818_c1312de67d70_alter_timetable_dim_columns.py +++ b/migrations/versions/20240818_0818_c1312de67d70_alter_timetable_dim_columns.py @@ -6,8 +6,6 @@ """ -import os - import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/20240828_1653_0bf7c70b7034_fix_diff_for_old_timetable.py b/migrations/versions/20240828_1653_0bf7c70b7034_fix_diff_for_old_timetable.py index c25febcd..5c3dd40d 100644 --- a/migrations/versions/20240828_1653_0bf7c70b7034_fix_diff_for_old_timetable.py +++ b/migrations/versions/20240828_1653_0bf7c70b7034_fix_diff_for_old_timetable.py @@ -6,8 +6,6 @@ """ -import os - import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/20240830_1617_f9426dfd57e2_change_to_nullable_events_id.py b/migrations/versions/20240830_1617_f9426dfd57e2_change_to_nullable_events_id.py index 0d925025..b722c2e5 100644 --- a/migrations/versions/20240830_1617_f9426dfd57e2_change_to_nullable_events_id.py +++ b/migrations/versions/20240830_1617_f9426dfd57e2_change_to_nullable_events_id.py @@ -6,8 +6,6 @@ """ -import os - import sqlalchemy as sa from alembic import op from sqlalchemy.dialects import postgresql diff --git a/migrations/versions/20240830_1700_f533a027d14a_new_w_dates.py b/migrations/versions/20240830_1700_f533a027d14a_new_w_dates.py index 6def3ea6..cfb94520 100644 --- a/migrations/versions/20240830_1700_f533a027d14a_new_w_dates.py +++ b/migrations/versions/20240830_1700_f533a027d14a_new_w_dates.py @@ -10,7 +10,6 @@ import sqlalchemy as sa from alembic import op -from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. diff --git a/migrations/versions/20240830_1754_eebd0dbc6839_add_link_full_schema.py b/migrations/versions/20240830_1754_eebd0dbc6839_add_link_full_schema.py index 00f6196e..defd5814 100644 --- a/migrations/versions/20240830_1754_eebd0dbc6839_add_link_full_schema.py +++ b/migrations/versions/20240830_1754_eebd0dbc6839_add_link_full_schema.py @@ -6,8 +6,6 @@ """ -import os - import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/20240830_1806_da280c5f1dac_add_link_full_schema2.py b/migrations/versions/20240830_1806_da280c5f1dac_add_link_full_schema2.py index 86e3de9d..78170495 100644 --- a/migrations/versions/20240830_1806_da280c5f1dac_add_link_full_schema2.py +++ b/migrations/versions/20240830_1806_da280c5f1dac_add_link_full_schema2.py @@ -6,11 +6,8 @@ """ -import os - import sqlalchemy as sa from alembic import op -from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. diff --git a/migrations/versions/20240830_1904_0e97fd76b68a_add_link_full_schema3.py b/migrations/versions/20240830_1904_0e97fd76b68a_add_link_full_schema3.py index 2c35caab..2bacf2ea 100644 --- a/migrations/versions/20240830_1904_0e97fd76b68a_add_link_full_schema3.py +++ b/migrations/versions/20240830_1904_0e97fd76b68a_add_link_full_schema3.py @@ -10,7 +10,6 @@ import sqlalchemy as sa from alembic import op -from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. diff --git a/migrations/versions/20241006_0726_5c0a5eb043d7_button_is_hidden.py b/migrations/versions/20241006_0726_5c0a5eb043d7_button_is_hidden.py index f58e948f..86224756 100644 --- a/migrations/versions/20241006_0726_5c0a5eb043d7_button_is_hidden.py +++ b/migrations/versions/20241006_0726_5c0a5eb043d7_button_is_hidden.py @@ -6,8 +6,6 @@ """ -import os - import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/20241008_0338_75df3cab6f2f_stg_userdata_param_validation.py b/migrations/versions/20241008_0338_75df3cab6f2f_stg_userdata_param_validation.py index ea6a4ac2..b094585f 100644 --- a/migrations/versions/20241008_0338_75df3cab6f2f_stg_userdata_param_validation.py +++ b/migrations/versions/20241008_0338_75df3cab6f2f_stg_userdata_param_validation.py @@ -6,8 +6,6 @@ """ -import os - import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/20241020_1405_ee89b52980d8_add_rating_api_tables.py b/migrations/versions/20241020_1405_ee89b52980d8_add_rating_api_tables.py index 67279941..df4c9ef8 100644 --- a/migrations/versions/20241020_1405_ee89b52980d8_add_rating_api_tables.py +++ b/migrations/versions/20241020_1405_ee89b52980d8_add_rating_api_tables.py @@ -10,7 +10,6 @@ import sqlalchemy as sa from alembic import op -from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. diff --git a/migrations/versions/20241020_1700_8253b11f2c82_merge_heads.py b/migrations/versions/20241020_1700_8253b11f2c82_merge_heads.py index ec2bba2a..fe584e70 100644 --- a/migrations/versions/20241020_1700_8253b11f2c82_merge_heads.py +++ b/migrations/versions/20241020_1700_8253b11f2c82_merge_heads.py @@ -6,12 +6,6 @@ """ -import os - -import sqlalchemy as sa -from alembic import op - - # revision identifiers, used by Alembic. revision = '8253b11f2c82' down_revision = ('75df3cab6f2f', 'ee89b52980d8') diff --git a/migrations/versions/20241103_1114_cf7557c43271_scds_for_userdata.py b/migrations/versions/20241103_1114_cf7557c43271_scds_for_userdata.py index fbdae1ee..c12a16f3 100644 --- a/migrations/versions/20241103_1114_cf7557c43271_scds_for_userdata.py +++ b/migrations/versions/20241103_1114_cf7557c43271_scds_for_userdata.py @@ -10,7 +10,6 @@ import sqlalchemy as sa from alembic import op -from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. diff --git a/migrations/versions/20241110_0936_0d19739e95cf_to_dwh.py b/migrations/versions/20241110_0936_0d19739e95cf_to_dwh.py index 6b88c7a6..d17966eb 100644 --- a/migrations/versions/20241110_0936_0d19739e95cf_to_dwh.py +++ b/migrations/versions/20241110_0936_0d19739e95cf_to_dwh.py @@ -10,7 +10,6 @@ import sqlalchemy as sa from alembic import op -from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. diff --git a/migrations/versions/20241110_1107_14b92d839a9b_monitoring.py b/migrations/versions/20241110_1107_14b92d839a9b_monitoring.py index 7dc1a119..37923419 100644 --- a/migrations/versions/20241110_1107_14b92d839a9b_monitoring.py +++ b/migrations/versions/20241110_1107_14b92d839a9b_monitoring.py @@ -10,7 +10,6 @@ import sqlalchemy as sa from alembic import op -from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. diff --git a/migrations/versions/20241110_1216_d56e230e4da9_fix.py b/migrations/versions/20241110_1216_d56e230e4da9_fix.py index 687b29e3..1b9954d6 100644 --- a/migrations/versions/20241110_1216_d56e230e4da9_fix.py +++ b/migrations/versions/20241110_1216_d56e230e4da9_fix.py @@ -10,7 +10,6 @@ import sqlalchemy as sa from alembic import op -from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. diff --git a/migrations/versions/20241110_1233_8ae074933b0d_fix2.py b/migrations/versions/20241110_1233_8ae074933b0d_fix2.py index 8c3ef59c..fdd88b44 100644 --- a/migrations/versions/20241110_1233_8ae074933b0d_fix2.py +++ b/migrations/versions/20241110_1233_8ae074933b0d_fix2.py @@ -10,7 +10,6 @@ import sqlalchemy as sa from alembic import op -from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. diff --git a/migrations/versions/20241110_1321_4744a389ff0b_stg_union_member_middle_name_add.py b/migrations/versions/20241110_1321_4744a389ff0b_stg_union_member_middle_name_add.py index a758236f..42be4f40 100644 --- a/migrations/versions/20241110_1321_4744a389ff0b_stg_union_member_middle_name_add.py +++ b/migrations/versions/20241110_1321_4744a389ff0b_stg_union_member_middle_name_add.py @@ -6,8 +6,6 @@ """ -import os - import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/20241112_0644_175a3aee3e1a_stg_userdata_param_visible_in_user_.py b/migrations/versions/20241112_0644_175a3aee3e1a_stg_userdata_param_visible_in_user_.py index 36054fb7..94d045c5 100644 --- a/migrations/versions/20241112_0644_175a3aee3e1a_stg_userdata_param_visible_in_user_.py +++ b/migrations/versions/20241112_0644_175a3aee3e1a_stg_userdata_param_visible_in_user_.py @@ -6,8 +6,6 @@ """ -import os - import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/20241117_1519_45b2b6c9d08c_added_visible_in_user_response_to_ods_.py b/migrations/versions/20241117_1519_45b2b6c9d08c_added_visible_in_user_response_to_ods_.py index 75dddd77..8e17ca8d 100644 --- a/migrations/versions/20241117_1519_45b2b6c9d08c_added_visible_in_user_response_to_ods_.py +++ b/migrations/versions/20241117_1519_45b2b6c9d08c_added_visible_in_user_response_to_ods_.py @@ -6,8 +6,6 @@ """ -import os - import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/20241130_1744_4662fc16ccde_.py b/migrations/versions/20241130_1744_4662fc16ccde_.py index a7912eca..45af2c4d 100644 --- a/migrations/versions/20241130_1744_4662fc16ccde_.py +++ b/migrations/versions/20241130_1744_4662fc16ccde_.py @@ -6,12 +6,6 @@ """ -import os - -import sqlalchemy as sa -from alembic import op - - # revision identifiers, used by Alembic. revision = '4662fc16ccde' down_revision = ('09416a9fa7cc', 'd47cdc452c99') diff --git a/migrations/versions/20241130_1906_d47cdc452c99_added_auth_email_into_dwh_user_info.py b/migrations/versions/20241130_1906_d47cdc452c99_added_auth_email_into_dwh_user_info.py index 932e2180..dee7e8dc 100644 --- a/migrations/versions/20241130_1906_d47cdc452c99_added_auth_email_into_dwh_user_info.py +++ b/migrations/versions/20241130_1906_d47cdc452c99_added_auth_email_into_dwh_user_info.py @@ -6,8 +6,6 @@ """ -import os - import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/20241211_1731_0d462525c992_change_links.py b/migrations/versions/20241211_1731_0d462525c992_change_links.py new file mode 100644 index 00000000..272549cd --- /dev/null +++ b/migrations/versions/20241211_1731_0d462525c992_change_links.py @@ -0,0 +1,414 @@ +"""change_links + +Revision ID: 0d462525c992 +Revises: f31bd2cf406f +Create Date: 2024-12-11 17:31:28.920934 + +""" + +import os + +import sqlalchemy as sa +from alembic import op + + +# revision identifiers, used by Alembic. +revision = '0d462525c992' +down_revision = 'f31bd2cf406f' +branch_labels = None +depends_on = None + + +def upgrade(): + # alembic cannot do it properly, so you need to manually handle columns + # ods_link_timetable_lesson + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_group drop COLUMN IF EXISTS id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_group add COLUMN IF not EXISTS id UUID') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_group drop COLUMN IF EXISTS group_id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_group add COLUMN IF not EXISTS group_id UUID') + # ods_link_timetable_group + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_lesson drop COLUMN IF EXISTS id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_lesson add COLUMN IF not EXISTS id UUID') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_lesson drop COLUMN IF EXISTS lesson_id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_lesson add COLUMN IF not EXISTS lesson_id UUID') + # ods_link_timetable_teacher + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_teacher drop COLUMN IF EXISTS id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_teacher add COLUMN IF not EXISTS id UUID') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_teacher drop COLUMN IF EXISTS teacher_id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_teacher add COLUMN IF not EXISTS teacher_id UUID') + # ods_timetable_act + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_timetable_act drop COLUMN IF EXISTS id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_timetable_act add COLUMN IF not EXISTS id UUID') + op.create_table( + 'ods_link_timetable_room', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column( + 'timetable_alias', + sa.String(), + nullable=True, + comment='Техническое поле для построения пайплайна сборки расписания', + ), + sa.Column( + 'event_id', + sa.UUID(), + nullable=True, + comment='Идентификатор события, полученного в результате парсинга ras.phys.msu', + ), + sa.Column('room_id', sa.UUID(), nullable=True), + sa.PrimaryKeyConstraint('id'), + schema='ODS_TIMETABLE', + ) + op.create_table( + 'ods_manual_timetable_constraints', + sa.Column( + 'event_id', + sa.UUID(), + nullable=False, + comment='Идентификатор события, полученного в результате парсинга ras.phys.msu', + ), + sa.Column('empty_room_flg', sa.UUID(), nullable=True, comment='Флаг: в событии не указан кабинет'), + sa.Column('empty_lecturer_flg', sa.UUID(), nullable=True, comment='Флаг: в событии не указан преподаватель'), + sa.Column('empty_group_flg', sa.UUID(), nullable=True, comment='Флаг: в событии не указан премет'), + sa.PrimaryKeyConstraint('event_id'), + schema='ODS_TIMETABLE', + ) + op.grant_on_table( + "test_dwh_ods_timetable_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_read", + ['SELECT'], + '"ODS_TIMETABLE".ods_link_timetable_room', + ) + op.grant_on_table( + "test_dwh_ods_timetable_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_write", + ['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], + '"ODS_TIMETABLE".ods_link_timetable_room', + ) + op.grant_on_table( + "test_dwh_ods_timetable_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_all", + ['ALL'], + '"ODS_TIMETABLE".ods_link_timetable_room', + ) + op.grant_on_table( + "test_dwh_ods_timetable_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_read", + ['SELECT'], + '"ODS_TIMETABLE".ods_manual_timetable_constraints', + ) + op.grant_on_table( + "test_dwh_ods_timetable_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_write", + ['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], + '"ODS_TIMETABLE".ods_manual_timetable_constraints', + ) + op.grant_on_table( + "test_dwh_ods_timetable_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_all", + ['ALL'], + '"ODS_TIMETABLE".ods_manual_timetable_constraints', + ) + op.drop_index( + 'ix_ODS_TIMETABLE_ods_link_timetable_cabinet_id', + table_name='ods_link_timetable_cabinet', + schema='ODS_TIMETABLE', + ) + op.revoke_on_table( + "test_dwh_ods_timetable_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_read", + ['SELECT'], + '"ODS_TIMETABLE".ods_link_timetable_cabinet', + ) + op.revoke_on_table( + "test_dwh_ods_timetable_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_write", + ['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], + '"ODS_TIMETABLE".ods_link_timetable_cabinet', + ) + op.revoke_on_table( + "test_dwh_ods_timetable_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_all", + ['ALL'], + '"ODS_TIMETABLE".ods_link_timetable_cabinet', + ) + op.add_column( + 'ods_link_timetable_group', + sa.Column( + 'timetable_alias', + sa.String(), + nullable=True, + comment='Техническое поле для построения пайплайна сборки расписания', + ), + schema='ODS_TIMETABLE', + ) + op.add_column( + 'ods_link_timetable_group', + sa.Column( + 'event_id', + sa.UUID(), + nullable=True, + comment='Идентификатор события, полученного в результате парсинга ras.phys.msu', + ), + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_group', + 'id', + existing_type=sa.INTEGER(), + type_=sa.UUID(), + nullable=False, + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_group', + 'group_id', + existing_type=sa.INTEGER(), + type_=sa.UUID(), + existing_nullable=True, + schema='ODS_TIMETABLE', + ) + op.add_column( + 'ods_link_timetable_lesson', + sa.Column( + 'timetable_alias', + sa.String(), + nullable=False, + comment='Техническое поле для построения пайплайна сборки расписания', + ), + schema='ODS_TIMETABLE', + ) + op.add_column( + 'ods_link_timetable_lesson', + sa.Column( + 'event_id', + sa.UUID(), + nullable=True, + comment='Идентификатор события, полученного в результате парсинга ras.phys.msu', + ), + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_lesson', + 'id', + existing_type=sa.INTEGER(), + type_=sa.UUID(), + nullable=False, + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_lesson', + 'lesson_id', + existing_type=sa.INTEGER(), + type_=sa.UUID(), + existing_nullable=True, + schema='ODS_TIMETABLE', + ) + op.drop_column('ods_link_timetable_lesson', 'group', schema='ODS_TIMETABLE') + op.drop_column('ods_link_timetable_lesson', 'event_tr', schema='ODS_TIMETABLE') + op.add_column( + 'ods_link_timetable_teacher', + sa.Column( + 'timetable_alias', + sa.String(), + nullable=False, + comment='Техническое поле для построения пайплайна сборки расписания', + ), + schema='ODS_TIMETABLE', + ) + op.add_column( + 'ods_link_timetable_teacher', + sa.Column( + 'event_id', + sa.UUID(), + nullable=True, + comment='Идентификатор события, полученного в результате парсинга ras.phys.msu', + ), + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_teacher', + 'id', + existing_type=sa.INTEGER(), + type_=sa.UUID(), + nullable=False, + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_teacher', + 'teacher_id', + existing_type=sa.INTEGER(), + type_=sa.UUID(), + existing_nullable=True, + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_timetable_act', 'id', existing_type=sa.INTEGER(), type_=sa.UUID(), nullable=False, schema='ODS_TIMETABLE' + ) + op.drop_table('ods_link_timetable_cabinet', schema='ODS_TIMETABLE') + + +def downgrade(): + # alembic cannot do it properly, so you need to manually handle columns + # ods_link_timetable_lesson + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_group drop COLUMN IF EXISTS id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_group add COLUMN IF not EXISTS id INTEGER') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_group drop COLUMN IF EXISTS group_id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_group add COLUMN IF not EXISTS group_id INTEGER') + # ods_link_timetable_group + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_lesson drop COLUMN IF EXISTS id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_lesson add COLUMN IF not EXISTS id INTEGER') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_lesson drop COLUMN IF EXISTS lesson_id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_lesson add COLUMN IF not EXISTS lesson_id INTEGER') + # ods_link_timetable_teacher + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_teacher drop COLUMN IF EXISTS id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_teacher add COLUMN IF not EXISTS id INTEGER') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_teacher drop COLUMN IF EXISTS teacher_id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_link_timetable_teacher add COLUMN IF not EXISTS teacher_id INTEGER') + # ods_timetable_act + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_timetable_act drop COLUMN IF EXISTS id') + op.execute('ALTER TABLE "ODS_TIMETABLE".ods_timetable_act add COLUMN IF not EXISTS id INTEGER') + op.create_table( + 'ods_link_timetable_cabinet', + sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), + sa.Column('group', sa.VARCHAR(), autoincrement=False, nullable=True), + sa.Column('event_tr', sa.VARCHAR(), autoincrement=False, nullable=True), + sa.Column('cabinet_id', sa.INTEGER(), autoincrement=False, nullable=True), + sa.PrimaryKeyConstraint('id', name='ods_link_timetable_cabinet_pkey'), + schema='ODS_TIMETABLE', + ) + op.create_index( + 'ix_ODS_TIMETABLE_ods_timetable_act_id', 'ods_timetable_act', ['id'], unique=False, schema='ODS_TIMETABLE' + ) + op.alter_column( + 'ods_timetable_act', 'id', existing_type=sa.UUID(), type_=sa.INTEGER(), nullable=True, schema='ODS_TIMETABLE' + ) + op.create_index( + 'ix_ODS_TIMETABLE_ods_link_timetable_teacher_id', + 'ods_link_timetable_teacher', + ['id'], + unique=False, + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_teacher', + 'teacher_id', + existing_type=sa.UUID(), + type_=sa.INTEGER(), + existing_nullable=True, + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_teacher', + 'id', + existing_type=sa.UUID(), + type_=sa.INTEGER(), + nullable=True, + schema='ODS_TIMETABLE', + ) + op.drop_column('ods_link_timetable_teacher', 'event_id', schema='ODS_TIMETABLE') + op.drop_column('ods_link_timetable_teacher', 'timetable_alias', schema='ODS_TIMETABLE') + op.add_column( + 'ods_link_timetable_lesson', + sa.Column('event_tr', sa.VARCHAR(), autoincrement=False, nullable=True), + schema='ODS_TIMETABLE', + ) + op.add_column( + 'ods_link_timetable_lesson', + sa.Column('group', sa.VARCHAR(), autoincrement=False, nullable=True), + schema='ODS_TIMETABLE', + ) + op.create_index( + 'ix_ODS_TIMETABLE_ods_link_timetable_lesson_id', + 'ods_link_timetable_lesson', + ['id'], + unique=False, + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_lesson', + 'lesson_id', + existing_type=sa.UUID(), + type_=sa.INTEGER(), + existing_nullable=True, + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_lesson', + 'id', + existing_type=sa.UUID(), + type_=sa.INTEGER(), + nullable=True, + schema='ODS_TIMETABLE', + ) + op.drop_column('ods_link_timetable_lesson', 'event_id', schema='ODS_TIMETABLE') + op.drop_column('ods_link_timetable_lesson', 'timetable_alias', schema='ODS_TIMETABLE') + op.create_index( + 'ix_ODS_TIMETABLE_ods_link_timetable_group_id', + 'ods_link_timetable_group', + ['id'], + unique=False, + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_group', + 'group_id', + existing_type=sa.UUID(), + type_=sa.INTEGER(), + existing_nullable=True, + schema='ODS_TIMETABLE', + ) + op.alter_column( + 'ods_link_timetable_group', + 'id', + existing_type=sa.UUID(), + type_=sa.INTEGER(), + nullable=True, + schema='ODS_TIMETABLE', + ) + op.drop_column('ods_link_timetable_group', 'event_id', schema='ODS_TIMETABLE') + op.drop_column('ods_link_timetable_group', 'timetable_alias', schema='ODS_TIMETABLE') + op.grant_on_table( + "test_dwh_ods_timetable_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_all", + ['ALL'], + '"ODS_TIMETABLE".ods_link_timetable_cabinet', + ) + op.grant_on_table( + "test_dwh_ods_timetable_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_write", + ['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], + '"ODS_TIMETABLE".ods_link_timetable_cabinet', + ) + op.grant_on_table( + "test_dwh_ods_timetable_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_read", + ['SELECT'], + '"ODS_TIMETABLE".ods_link_timetable_cabinet', + ) + op.create_index( + 'ix_ODS_TIMETABLE_ods_link_timetable_cabinet_id', + 'ods_link_timetable_cabinet', + ['id'], + unique=False, + schema='ODS_TIMETABLE', + ) + op.revoke_on_table( + "test_dwh_ods_timetable_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_all", + ['ALL'], + '"ODS_TIMETABLE".ods_manual_timetable_constraints', + ) + op.revoke_on_table( + "test_dwh_ods_timetable_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_write", + ['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], + '"ODS_TIMETABLE".ods_manual_timetable_constraints', + ) + op.revoke_on_table( + "test_dwh_ods_timetable_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_read", + ['SELECT'], + '"ODS_TIMETABLE".ods_manual_timetable_constraints', + ) + op.revoke_on_table( + "test_dwh_ods_timetable_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_all", + ['ALL'], + '"ODS_TIMETABLE".ods_link_timetable_room', + ) + op.revoke_on_table( + "test_dwh_ods_timetable_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_write", + ['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], + '"ODS_TIMETABLE".ods_link_timetable_room', + ) + op.revoke_on_table( + "test_dwh_ods_timetable_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_timetable_read", + ['SELECT'], + '"ODS_TIMETABLE".ods_link_timetable_room', + ) + op.drop_table('ods_manual_timetable_constraints', schema='ODS_TIMETABLE') + op.drop_table('ods_link_timetable_room', schema='ODS_TIMETABLE') diff --git a/profcomff_definitions/DWH/user_info.py b/profcomff_definitions/DWH/user_info.py index 7a0af09c..28fbd8aa 100644 --- a/profcomff_definitions/DWH/user_info.py +++ b/profcomff_definitions/DWH/user_info.py @@ -1,5 +1,3 @@ -from datetime import date, datetime - from sqlalchemy import Integer, String from sqlalchemy.orm import Mapped, mapped_column diff --git a/profcomff_definitions/ODS/auth.py b/profcomff_definitions/ODS/auth.py index 03c53ebe..f842856d 100644 --- a/profcomff_definitions/ODS/auth.py +++ b/profcomff_definitions/ODS/auth.py @@ -1,6 +1,6 @@ from datetime import date, datetime -from sqlalchemy.orm import Mapped, mapped_column +from sqlalchemy.orm import Mapped from profcomff_definitions.base import Base diff --git a/profcomff_definitions/ODS/info.py b/profcomff_definitions/ODS/info.py index b3471e34..a6f5129d 100644 --- a/profcomff_definitions/ODS/info.py +++ b/profcomff_definitions/ODS/info.py @@ -1,7 +1,6 @@ from datetime import date, datetime -from sqlalchemy import Integer, String -from sqlalchemy.orm import Mapped, mapped_column +from sqlalchemy.orm import Mapped from profcomff_definitions.base import Base diff --git a/profcomff_definitions/ODS/timetable.py b/profcomff_definitions/ODS/timetable.py index 88f4206e..157ae70d 100644 --- a/profcomff_definitions/ODS/timetable.py +++ b/profcomff_definitions/ODS/timetable.py @@ -1,4 +1,6 @@ -from sqlalchemy import Integer, String +import uuid + +from sqlalchemy import UUID, String from sqlalchemy.orm import Mapped, mapped_column from profcomff_definitions.base import Base @@ -10,7 +12,7 @@ class OdsTimetableAct(Base): Выделяется блок текста из общей таблицы, нужна для обновления расписания в приложении ТвойФФ """ - id: Mapped[int] = mapped_column(Integer, index=True, primary_key=True) + id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) name: Mapped[str] = mapped_column(comment="Название события") odd: Mapped[bool] = mapped_column(comment="Флаг: событие относится к нечетной неделе") even: Mapped[bool] = mapped_column(comment="Флаг: событие относится к четной неделе") @@ -22,28 +24,84 @@ class OdsTimetableAct(Base): class OdsLinkTimetableTeacher(Base): - id: Mapped[int] = mapped_column(Integer, index=True, primary_key=True) - group: Mapped[str | None] = mapped_column(String, nullable=True) - event_tr: Mapped[str | None] = mapped_column(String, nullable=True) - teacher_id: Mapped[str | None] = mapped_column(Integer, nullable=True) + id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) + timetable_alias: Mapped[str] = mapped_column( + String, comment="Техническое поле для построения пайплайна сборки расписания" + ) + event_id: Mapped[uuid.UUID] = mapped_column( + UUID, + comment="Идентификатор события, полученного в результате парсинга ras.phys.msu", + nullable=True, + ) + teacher_id: Mapped[uuid.UUID | None] = mapped_column(UUID, nullable=True) class OdsLinkTimetableLesson(Base): - id: Mapped[int] = mapped_column(Integer, index=True, primary_key=True) - group: Mapped[str | None] = mapped_column(String, nullable=True) - event_tr: Mapped[str | None] = mapped_column(String, nullable=True) - lesson_id: Mapped[str | None] = mapped_column(Integer, nullable=True) + id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) + timetable_alias: Mapped[str] = mapped_column( + String, comment="Техническое поле для построения пайплайна сборки расписания" + ) + event_id: Mapped[uuid.UUID] = mapped_column( + UUID, + comment="Идентификатор события, полученного в результате парсинга ras.phys.msu", + nullable=True, + ) + lesson_id: Mapped[uuid.UUID | None] = mapped_column(UUID, nullable=True) class OdsLinkTimetableGroup(Base): - id: Mapped[int] = mapped_column(Integer, index=True, primary_key=True) - group: Mapped[str | None] = mapped_column(String, nullable=True) - event_tr: Mapped[str | None] = mapped_column(String, nullable=True) - group_id: Mapped[str | None] = mapped_column(Integer, nullable=True) + id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) + timetable_alias: Mapped[str] = mapped_column( + String, + comment="Техническое поле для построения пайплайна сборки расписания", + nullable=True, + ) + event_id: Mapped[uuid.UUID] = mapped_column( + UUID, + comment="Идентификатор события, полученного в результате парсинга ras.phys.msu", + nullable=True, + ) + group_id: Mapped[uuid.UUID | None] = mapped_column(UUID, nullable=True) + + +class OdsLinkTimetableRoom(Base): + id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) + timetable_alias: Mapped[str] = mapped_column( + String, + comment="Техническое поле для построения пайплайна сборки расписания", + nullable=True, + ) + event_id: Mapped[uuid.UUID] = mapped_column( + UUID, + comment="Идентификатор события, полученного в результате парсинга ras.phys.msu", + nullable=True, + ) + room_id: Mapped[uuid.UUID | None] = mapped_column(UUID, nullable=True) -class OdsLinkTimetableCabinet(Base): - id: Mapped[int] = mapped_column(Integer, index=True, primary_key=True) - group: Mapped[str | None] = mapped_column(String, nullable=True) - event_tr: Mapped[str | None] = mapped_column(String, nullable=True) - cabinet_id: Mapped[str | None] = mapped_column(Integer, nullable=True) +class OdsManualTimetableConstraints(Base): + event_id: Mapped[uuid.UUID] = mapped_column( + UUID, + comment="Идентификатор события, полученного в результате парсинга ras.phys.msu", + primary_key=True, + ) + empty_room_flg: Mapped[uuid.UUID] = mapped_column( + UUID, + comment="Флаг: в событии не указан кабинет", + nullable=True, + ) + empty_lecturer_flg: Mapped[uuid.UUID] = mapped_column( + UUID, + comment="Флаг: в событии не указан преподаватель", + nullable=True, + ) + empty_group_flg: Mapped[uuid.UUID] = mapped_column( + UUID, + comment="Флаг: в событии не указана группа", + nullable=True, + ) + empty_group_flg: Mapped[uuid.UUID] = mapped_column( + UUID, + comment="Флаг: в событии не указан премет", + nullable=True, + ) diff --git a/requirements.dev.txt b/requirements.dev.txt index 8c044d8a..4c2fafdb 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -7,4 +7,4 @@ httpx isort pytest pytest-cov -requests \ No newline at end of file +requests diff --git a/requirements.txt b/requirements.txt index 7c31846a..b041a90e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ SQLAlchemy psycopg2-binary -python-dotenv \ No newline at end of file +python-dotenv +uuid