-
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.
Showing
2 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
migrations/versions/20250222_0952_2d7609e6f490_dm_comment_2.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,144 @@ | ||
"""dm_comment_2 | ||
Revision ID: 2d7609e6f490 | ||
Revises: 41490fd26134 | ||
Create Date: 2025-02-22 09:52:54.267898 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import os | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '2d7609e6f490' | ||
down_revision = '41490fd26134' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table_schema("DM_RATING") | ||
op.create_table( | ||
'dm_lecturer_comment_act', | ||
sa.Column('comment_api_uuid', sa.Uuid(), nullable=False, comment='Идентифиактор в rating-api'), | ||
sa.Column('lecturer_api_id', sa.Integer(), nullable=False, comment='Идентифиактор в rating-api'), | ||
sa.Column('lecturer_full_name', sa.String(), nullable=True, comment='ФИО преподавателя'), | ||
sa.Column('lecturer_first_name', sa.String(), nullable=True, comment='Имя преподавателя'), | ||
sa.Column('lecturer_last_name', sa.String(), nullable=True, comment='Фамилия преподавателя'), | ||
sa.Column('lecturer_middle_name', sa.String(), nullable=True, comment='ОТчество преподавателя'), | ||
sa.Column('timetable_id', sa.Integer(), nullable=True, comment='Идертификатор в timetable-api'), | ||
sa.Column('has_timetable_id', sa.Boolean(), nullable=False, comment='Флаг: есть ли преподаватель в расписании'), | ||
sa.Column('lecturer_subject', sa.String(), nullable=True, comment='Предмет, относящийся к преподавателю'), | ||
sa.Column('comment_subject', sa.String(), nullable=True, comment='Оцениваемый предмет'), | ||
sa.Column( | ||
'comment_shortened_text', sa.String(), nullable=True, comment='Первые 80 символов текста комментария' | ||
), | ||
sa.Column('comment_full_text', sa.String(), nullable=True, comment='Полный текст комментария'), | ||
sa.Column('comment_create_ts', sa.DateTime(), nullable=True, comment='Timestamp создания комментария, мск'), | ||
sa.Column('comment_update_ts', sa.DateTime(), nullable=True, comment='Timestamp обновления комментария, мск'), | ||
sa.Column('comment_mark_kindness', sa.Integer(), nullable=False, comment='Оценка доброты'), | ||
sa.Column('comment_mark_freebie', sa.Integer(), nullable=False, comment='Оценка халявности'), | ||
sa.Column('comment_mark_clarity', sa.Integer(), nullable=False, comment='Оценка понятности'), | ||
sa.Column('comment_review_status', sa.String(), nullable=False, comment='Статус комментария'), | ||
sa.Column('user_id', sa.Integer(), nullable=True, comment='Идентификатор пользователя из auth-api'), | ||
sa.Column('user_full_name', sa.String(), nullable=True, comment='Имя пользователя'), | ||
sa.Column('user_email', sa.String(), nullable=True, comment='Список электронных почт пользователя'), | ||
schema='DM_RATING', | ||
comment='\n Snapshot table that shows sizes for all tables in DWH\n ', | ||
info={'sensitive': False}, | ||
) | ||
op.create_group( | ||
"test_dwh_dm_rating_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_read" | ||
) | ||
op.create_group( | ||
"test_dwh_dm_rating_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_write" | ||
) | ||
op.create_group("test_dwh_dm_rating_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_all") | ||
op.grant_on_schema( | ||
"test_dwh_dm_rating_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_read", | ||
"DM_RATING", | ||
) | ||
op.grant_on_schema( | ||
"test_dwh_dm_rating_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_write", | ||
"DM_RATING", | ||
) | ||
op.grant_on_schema( | ||
"test_dwh_dm_rating_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_all", "DM_RATING" | ||
) | ||
op.grant_on_table( | ||
"test_dwh_dm_rating_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_read", | ||
['SELECT'], | ||
'"DM_RATING".dm_lecturer_comment_act', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_dm_rating_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_write", | ||
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], | ||
'"DM_RATING".dm_lecturer_comment_act', | ||
) | ||
op.grant_on_table( | ||
"test_dwh_dm_rating_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_all", | ||
['ALL'], | ||
'"DM_RATING".dm_lecturer_comment_act', | ||
) | ||
op.create_index( | ||
op.f('ix_DM_RATING_dm_lecturer_comment_act_comment_create_ts'), | ||
'dm_lecturer_comment_act', | ||
['comment_create_ts'], | ||
unique=False, | ||
schema='DM_RATING', | ||
) | ||
op.create_index( | ||
op.f('ix_DM_RATING_dm_lecturer_comment_act_user_id'), | ||
'dm_lecturer_comment_act', | ||
['user_id'], | ||
unique=False, | ||
schema='DM_RATING', | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_index( | ||
op.f('ix_DM_RATING_dm_lecturer_comment_act_user_id'), table_name='dm_lecturer_comment_act', schema='DM_RATING' | ||
) | ||
op.drop_index( | ||
op.f('ix_DM_RATING_dm_lecturer_comment_act_comment_create_ts'), | ||
table_name='dm_lecturer_comment_act', | ||
schema='DM_RATING', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_dm_rating_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_all", | ||
['ALL'], | ||
'"DM_RATING".dm_lecturer_comment_act', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_dm_rating_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_write", | ||
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'], | ||
'"DM_RATING".dm_lecturer_comment_act', | ||
) | ||
op.revoke_on_table( | ||
"test_dwh_dm_rating_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_read", | ||
['SELECT'], | ||
'"DM_RATING".dm_lecturer_comment_act', | ||
) | ||
op.revoke_on_schema( | ||
"test_dwh_dm_rating_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_all", "DM_RATING" | ||
) | ||
op.revoke_on_schema( | ||
"test_dwh_dm_rating_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_write", | ||
"DM_RATING", | ||
) | ||
op.revoke_on_schema( | ||
"test_dwh_dm_rating_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_read", | ||
"DM_RATING", | ||
) | ||
op.drop_table('dm_lecturer_comment_act', schema='DM_RATING') | ||
op.delete_group("test_dwh_dm_rating_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_all") | ||
op.delete_group( | ||
"test_dwh_dm_rating_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_write" | ||
) | ||
op.delete_group( | ||
"test_dwh_dm_rating_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_rating_read" | ||
) | ||
op.drop_table_schema("DM_RATING") |
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,38 @@ | ||
from datetime import date, datetime | ||
from uuid import UUID | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
from sqlalchemy import schema | ||
from profcomff_definitions.base import Base | ||
|
||
|
||
class DmLecturerCommentAct(Base): | ||
""" | ||
Snapshot table that shows sizes for all tables in DWH | ||
""" | ||
comment_api_uuid: Mapped[UUID] = mapped_column(comment="Идентифиактор в rating-api") | ||
lecturer_api_id: Mapped[int] = mapped_column(comment="Идентифиактор в rating-api") | ||
lecturer_full_name: Mapped[str | None] = mapped_column(comment="ФИО преподавателя") | ||
lecturer_first_name: Mapped[str | None] = mapped_column(comment="Имя преподавателя") | ||
lecturer_last_name: Mapped[str | None] = mapped_column(comment="Фамилия преподавателя") | ||
lecturer_middle_name: Mapped[str | None] = mapped_column(comment="ОТчество преподавателя") | ||
timetable_id: Mapped[int | None] = mapped_column(comment="Идертификатор в timetable-api") | ||
has_timetable_id: Mapped[bool] = mapped_column(comment="Флаг: есть ли преподаватель в расписании") | ||
lecturer_subject: Mapped[str | None] = mapped_column(comment="Предмет, относящийся к преподавателю") | ||
comment_subject: Mapped[str | None] = mapped_column(comment="Оцениваемый предмет") | ||
comment_shortened_text: Mapped[str | None] = mapped_column(comment="Первые 80 символов текста комментария") | ||
comment_full_text: Mapped[str | None] = mapped_column(comment="Полный текст комментария") | ||
comment_create_ts: Mapped[datetime | None] = mapped_column(comment="Timestamp создания комментария, мск", index=True) | ||
comment_update_ts: Mapped[datetime | None] = mapped_column(comment="Timestamp обновления комментария, мск") | ||
comment_mark_kindness: Mapped[int] = mapped_column(comment="Оценка доброты") | ||
comment_mark_freebie: Mapped[int] = mapped_column(comment="Оценка халявности") | ||
comment_mark_clarity: Mapped[int] = mapped_column(comment="Оценка понятности") | ||
comment_review_status: Mapped[str] = mapped_column(comment="Статус комментария") | ||
user_id: Mapped[int | None] = mapped_column(comment="Идентификатор пользователя из auth-api", index=True) | ||
user_full_name: Mapped[str | None] = mapped_column(comment="Имя пользователя") | ||
user_email: Mapped[str | None] = mapped_column(comment="Список электронных почт пользователя") | ||
__mapper_args__ = {"primary_key": ["comment_api_uuid", "lecturer_api_id"]} | ||
__table_args__ = ( | ||
schema.Index("ix__dm_lecturer_comment_act__user_full_name", "user_full_name", postgresql_using="gin"), | ||
schema.Index("ix__dm_lecturer_comment_act__lecturer_full_name", "lecturer_full_name", postgresql_using="gin"), | ||
schema.Index("ix__dm_lecturer_comment_act__comment_shortened_text", "comment_shortened_text", postgresql_using="gin"), | ||
) |