Skip to content

Commit

Permalink
#44 (#53)
Browse files Browse the repository at this point in the history
## Изменения
44 на нужной ветке
## Детали реализации
<!-- Здесь можно описать технические детали по пунктам. -->

## Check-List
<!-- После сохранения у следующих полей появятся галочки, которые нужно
проставить мышкой -->
- [ ] Вы проверили свой код перед отправкой запроса?
- [ ] Вы написали тесты к реализованным функциям?
- [ ] Вы не забыли применить форматирование `black` и `isort` для
_Back-End_ или `Prettier` для _Front-End_?
  • Loading branch information
SofyaFin authored Jun 25, 2024
1 parent 51b7216 commit 13ea7e3
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"""

from alembic import op
import sqlalchemy as sa
import os

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '8b6f4a99f692'
down_revision = 'd459997cd681'
Expand Down
5 changes: 3 additions & 2 deletions migrations/versions/20240512_0913_7353088d02ce_.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"""

from alembic import op
import sqlalchemy as sa
import os

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '7353088d02ce'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ def upgrade():
sa.Column('security_and_analysis_secret_scanning_validity_checks_status', sa.String(), nullable=True),
schema='STG_GITHUB',
)
op.alter_column(
'profcomff_issue', 'id', existing_type=sa.INTEGER(), type_=sa.BIGINT(), schema='STG_GITHUB'
)
op.alter_column('profcomff_issue', 'id', existing_type=sa.INTEGER(), type_=sa.BIGINT(), schema='STG_GITHUB')


def downgrade():
op.alter_column(
'profcomff_issue', 'id', existing_type=sa.BIGINT(), type_=sa.INTEGER(), schema='STG_GITHUB'
)
op.alter_column('profcomff_issue', 'id', existing_type=sa.BIGINT(), type_=sa.INTEGER(), schema='STG_GITHUB')
op.drop_column(
'profcomff_repo', 'security_and_analysis_secret_scanning_validity_checks_status', schema='STG_GITHUB'
)
Expand Down
72 changes: 72 additions & 0 deletions migrations/versions/20240625_1206_5714921e11a0_incident_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""incident_logs
Revision ID: 5714921e11a0
Revises: 7a18bd9ff633
Create Date: 2024-06-25 12:06:54.755277
"""

import os

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '5714921e11a0'
down_revision = '7a18bd9ff633'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
'incident_hint',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('msk_record_loaded_dttm', sa.DateTime(), nullable=False, comment='Поле нарезки лога'),
sa.Column(
'container_name', sa.String(), nullable=False, comment='Имя контейнера, в котором произошла ошибочка'
),
sa.Column('message', sa.String(), nullable=False, comment='Сообщение об ошибке'),
sa.Column('create_ts', sa.DateTime(), nullable=False, comment='Время, когда произошла ошибка'),
sa.PrimaryKeyConstraint('id'),
schema='DM_INFRA_LOGS',
comment='Информация об ошибках по контейнерам',
)
op.grant_on_table(
"test_dwh_dm_infra_logs_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_infra_logs_read",
['SELECT'],
'"DM_INFRA_LOGS".incident_hint',
)
op.grant_on_table(
"test_dwh_dm_infra_logs_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_infra_logs_write",
['SELECT', 'INSERT', 'DELETE', 'UPDATE', 'TRUNCATE'],
'"DM_INFRA_LOGS".incident_hint',
)
op.grant_on_table(
"test_dwh_dm_infra_logs_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_infra_logs_all",
['ALL'],
'"DM_INFRA_LOGS".incident_hint',
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.revoke_on_table(
"test_dwh_dm_infra_logs_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_infra_logs_all",
['ALL'],
'"DM_INFRA_LOGS".incident_hint',
)
op.revoke_on_table(
"test_dwh_dm_infra_logs_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_infra_logs_write",
['SELECT', 'INSERT', 'DELETE', 'UPDATE', 'TRUNCATE'],
'"DM_INFRA_LOGS".incident_hint',
)
op.revoke_on_table(
"test_dwh_dm_infra_logs_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_dm_infra_logs_read",
['SELECT'],
'"DM_INFRA_LOGS".incident_hint',
)
op.drop_table('incident_hint', schema='DM_INFRA_LOGS')
12 changes: 12 additions & 0 deletions profcomff_definitions/DM/infra_logs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from sqlalchemy.orm import Mapped, mapped_column

from profcomff_definitions.base import Base
Expand All @@ -15,3 +17,13 @@ class ContainerLogCube(Base):
error_cnt: Mapped[int] = mapped_column(comment="Количество записей с типом ERROR")
critical_cnt: Mapped[int] = mapped_column(comment="Количество записей с типом CRITICAL")
other_cnt: Mapped[int] = mapped_column(comment="Количество записей с другими типами")


class IncidentHint(Base):
"""Информация об ошибках по контейнерам"""

id: Mapped[int] = mapped_column(primary_key=True)
msk_record_loaded_dttm: Mapped[datetime] = mapped_column(comment="Поле нарезки лога")
container_name: Mapped[str] = mapped_column(comment="Имя контейнера, в котором произошла ошибочка")
message: Mapped[str] = mapped_column(comment="Сообщение об ошибке")
create_ts: Mapped[datetime] = mapped_column(comment="Время, когда произошла ошибка")
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from typing import Generator

import pytest
from alembic.config import Config
from sqlalchemy import create_engine
from alembic.command import downgrade, upgrade, revision
from alembic.command import downgrade, revision, upgrade
from alembic.config import Config
from alembic.script import Script, ScriptDirectory
from sqlalchemy import create_engine
from sqlalchemy.engine import Engine


Expand All @@ -18,7 +17,9 @@
def alembic_config():
alembic_cfg = Config()
alembic_cfg.set_main_option('script_location', str(REPO_ROOT / "migrations"))
alembic_cfg.set_main_option('sqlalchemy.url', os.getenv("DB_DSN") or "postgresql://postgres:postgres@localhost:5432/postgres") # db for migration tests
alembic_cfg.set_main_option(
'sqlalchemy.url', os.getenv("DB_DSN") or "postgresql://postgres:postgres@localhost:5432/postgres"
) # db for migration tests
return alembic_cfg


Expand Down

0 comments on commit 13ea7e3

Please sign in to comment.