-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Изменения <!-- Опишите здесь на языке, понятном каждому, изменения, сделанные в исходном коде по пунктам. --> ## Детали реализации <!-- Здесь можно описать технические детали по пунктам. --> ## Check-List <!-- После сохранения у следующих полей появятся галочки, которые нужно проставить мышкой --> - [x] Вы проверили свой код перед отправкой запроса? - [ ] Вы написали тесты к реализованным функциям? - [x] Вы не забыли применить форматирование `black` и `isort` для _Back-End_ или `Prettier` для _Front-End_? #55
- Loading branch information
Showing
6 changed files
with
322 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
Create Date: 2024-07-23 18:29:37.398287 | ||
""" | ||
|
||
import os | ||
|
||
import sqlalchemy as sa | ||
|
275 changes: 275 additions & 0 deletions
275
migrations/versions/20240803_1005_ec6f952103aa_schemas_to_store_mymsuapi_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,275 @@ | ||
"""schemas to store mymsuapi data | ||
Revision ID: ec6f952103aa | ||
Revises: 0801e032e4e7 | ||
Create Date: 2024-08-03 10:05:03.253825 | ||
""" | ||
|
||
import os | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
|
||
revision = 'ec6f952103aa' | ||
down_revision = '0801e032e4e7' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table_schema("ODS_MYMSUAPI") | ||
op.create_table_schema("STG_MYMSUAPI") | ||
op.create_table( | ||
'ods_timetable_api_flattened', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('group_name', sa.String(), nullable=False), | ||
sa.Column('discipline_name', sa.String(), nullable=False), | ||
sa.Column('discipline_id', sa.Integer(), nullable=False), | ||
sa.Column('classroom_name', sa.String(), nullable=False), | ||
sa.Column('classroom_id', sa.Integer(), nullable=False), | ||
sa.Column('lesson_type_text', sa.String(), nullable=False), | ||
sa.Column('lesson_from_dttm_ts', sa.DateTime(), nullable=False), | ||
sa.Column('lesson_to_dttm_ts', sa.DateTime(), nullable=False), | ||
sa.Column('teacher_full_name', sa.String(), nullable=False), | ||
sa.Column('study_group_id', sa.Integer(), nullable=False), | ||
sa.Column('study_group_name', sa.String(), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
schema='ODS_MYMSUAPI', | ||
) | ||
op.create_table( | ||
'raw_timetable_api', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('group_name', sa.String(), nullable=False), | ||
sa.Column('discipline_name', sa.String(), nullable=False), | ||
sa.Column('discipline_id', sa.Integer(), nullable=False), | ||
sa.Column('classroom_name', sa.String(), nullable=False), | ||
sa.Column('classroom_id', sa.Integer(), nullable=False), | ||
sa.Column('lesson_type_text', sa.String(), nullable=False), | ||
sa.Column('lesson_from_dttm_ts', sa.TIMESTAMP(), nullable=False), | ||
sa.Column('lesson_to_dttm_ts', sa.TIMESTAMP(), nullable=False), | ||
sa.Column('teacher_users', sa.JSON(), nullable=False), | ||
sa.Column('study_groups', sa.JSON(), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
schema='STG_MYMSUAPI', | ||
) | ||
op.create_group( | ||
"test_dwh_ods_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_read" | ||
) | ||
op.create_group( | ||
"test_dwh_ods_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_write" | ||
) | ||
op.create_group( | ||
"test_dwh_ods_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_all" | ||
) | ||
op.create_group( | ||
"test_dwh_stg_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_read" | ||
) | ||
op.create_group( | ||
"test_dwh_stg_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_write" | ||
) | ||
op.create_group( | ||
"test_dwh_stg_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_all" | ||
) | ||
op.grant_on_schema( | ||
"test_dwh_ods_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_read", | ||
"ODS_MYMSUAPI", | ||
) | ||
op.grant_on_schema( | ||
"test_dwh_ods_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_write", | ||
"ODS_MYMSUAPI", | ||
) | ||
op.grant_on_schema( | ||
"test_dwh_ods_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_all", | ||
"ODS_MYMSUAPI", | ||
) | ||
op.grant_on_schema( | ||
"test_dwh_stg_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_read", | ||
"STG_MYMSUAPI", | ||
) | ||
op.grant_on_schema( | ||
"test_dwh_stg_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_write", | ||
"STG_MYMSUAPI", | ||
) | ||
op.grant_on_schema( | ||
"test_dwh_stg_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_all", | ||
"STG_MYMSUAPI", | ||
) | ||
op.grant_on_table( | ||
"test_dwh_ods_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_read", | ||
['SELECT'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_ods_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_write", | ||
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_ods_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_all", | ||
['ALL'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_stg_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_read", | ||
['SELECT'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_stg_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_write", | ||
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_stg_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_all", | ||
['ALL'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_ods_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_read", | ||
['SELECT'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_ods_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_write", | ||
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_ods_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_all", | ||
['ALL'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_stg_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_read", | ||
['SELECT'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_stg_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_write", | ||
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_stg_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_all", | ||
['ALL'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.add_column('dim_event_act', sa.Column('source_name', sa.String(), nullable=False), schema='DM_TIMETABLE') | ||
op.add_column('dim_group_act', sa.Column('source_name', sa.String(), nullable=False), schema='DM_TIMETABLE') | ||
op.add_column('dim_lecturer_act', sa.Column('source_name', sa.String(), nullable=False), schema='DM_TIMETABLE') | ||
op.add_column('dim_room_act', sa.Column('source_name', sa.String(), nullable=False), schema='DM_TIMETABLE') | ||
|
||
|
||
def downgrade(): | ||
op.drop_column('dim_room_act', 'source_name', schema='DM_TIMETABLE') | ||
op.drop_column('dim_lecturer_act', 'source_name', schema='DM_TIMETABLE') | ||
op.drop_column('dim_group_act', 'source_name', schema='DM_TIMETABLE') | ||
op.drop_column('dim_event_act', 'source_name', schema='DM_TIMETABLE') | ||
op.revoke_on_table( | ||
"test_dwh_stg_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_all", | ||
['ALL'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_stg_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_write", | ||
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_stg_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_read", | ||
['SELECT'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_ods_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_all", | ||
['ALL'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_ods_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_write", | ||
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_ods_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_read", | ||
['SELECT'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_stg_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_all", | ||
['ALL'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_stg_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_write", | ||
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_stg_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_read", | ||
['SELECT'], | ||
'"STG_MYMSUAPI".raw_timetable_api', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_ods_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_all", | ||
['ALL'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_ods_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_write", | ||
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_ods_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_read", | ||
['SELECT'], | ||
'"ODS_MYMSUAPI".ods_timetable_api_flattened', | ||
) | ||
op.revoke_on_schema( | ||
"test_dwh_stg_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_all", | ||
"STG_MYMSUAPI", | ||
) | ||
op.revoke_on_schema( | ||
"test_dwh_stg_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_write", | ||
"STG_MYMSUAPI", | ||
) | ||
op.revoke_on_schema( | ||
"test_dwh_stg_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_read", | ||
"STG_MYMSUAPI", | ||
) | ||
op.revoke_on_schema( | ||
"test_dwh_ods_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_all", | ||
"ODS_MYMSUAPI", | ||
) | ||
op.revoke_on_schema( | ||
"test_dwh_ods_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_write", | ||
"ODS_MYMSUAPI", | ||
) | ||
op.revoke_on_schema( | ||
"test_dwh_ods_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_read", | ||
"ODS_MYMSUAPI", | ||
) | ||
op.drop_table('raw_timetable_api', schema='STG_MYMSUAPI') | ||
op.drop_table('ods_timetable_api_flattened', schema='ODS_MYMSUAPI') | ||
op.delete_group( | ||
"test_dwh_stg_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_all" | ||
) | ||
op.delete_group( | ||
"test_dwh_stg_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_write" | ||
) | ||
op.delete_group( | ||
"test_dwh_stg_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_mymsuapi_read" | ||
) | ||
op.delete_group( | ||
"test_dwh_ods_mymsuapi_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_all" | ||
) | ||
op.delete_group( | ||
"test_dwh_ods_mymsuapi_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_write" | ||
) | ||
op.delete_group( | ||
"test_dwh_ods_mymsuapi_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_ods_mymsuapi_read" | ||
) | ||
op.drop_table_schema("STG_MYMSUAPI") | ||
op.drop_table_schema("ODS_MYMSUAPI") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from datetime import datetime | ||
|
||
from sqlalchemy import TIMESTAMP | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
from profcomff_definitions.base import Base | ||
|
||
|
||
class OdsTimetableApiFlattened(Base): | ||
id: Mapped[int] = mapped_column(primary_key=True) | ||
group_name: Mapped[str] | ||
discipline_name: Mapped[str] | ||
discipline_id: Mapped[int] | ||
classroom_name: Mapped[str] | ||
classroom_id: Mapped[int] | ||
lesson_type_text: Mapped[str] | ||
lesson_from_dttm_ts: Mapped[datetime] | ||
lesson_to_dttm_ts: Mapped[datetime] | ||
teacher_full_name: Mapped[str] | ||
study_group_id: Mapped[int] | ||
study_group_name: Mapped[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from datetime import datetime | ||
|
||
from sqlalchemy import JSON, TIMESTAMP | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
from profcomff_definitions.base import Base | ||
|
||
|
||
class RawTimetableApi(Base): | ||
id: Mapped[int] = mapped_column(primary_key=True) | ||
group_name: Mapped[str] | ||
discipline_name: Mapped[str] | ||
discipline_id: Mapped[int] | ||
classroom_name: Mapped[str] | ||
classroom_id: Mapped[int] | ||
lesson_type_text: Mapped[str] | ||
lesson_from_dttm_ts: Mapped[datetime] = mapped_column(TIMESTAMP) | ||
lesson_to_dttm_ts: Mapped[datetime] = mapped_column(TIMESTAMP) | ||
teacher_users: Mapped[dict] = mapped_column(JSON) | ||
study_groups: Mapped[dict] = mapped_column(JSON) |