Skip to content

Commit

Permalink
Infra logs (#40)
Browse files Browse the repository at this point in the history
## Изменения
Добавил таблицу для инфраструктурных логов
  • Loading branch information
dyakovri authored May 7, 2024
1 parent 190d25e commit 0db067c
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
4 changes: 2 additions & 2 deletions migrations/versions/45f0a9e06fca_add_social_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
Create Date: 2024-05-07 00:35:19.238888
"""
from alembic import op

import sqlalchemy as sa
import os
from alembic import op


# revision identifiers, used by Alembic.
Expand Down
83 changes: 83 additions & 0 deletions migrations/versions/6f659c404b5f_add_container_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""Add container log
Revision ID: 6f659c404b5f
Revises: 45f0a9e06fca
Create Date: 2024-05-07 02:46:24.397656
"""

import os

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '6f659c404b5f'
down_revision = '45f0a9e06fca'
branch_labels = None
depends_on = None


def upgrade():
op.create_table_schema("STG_INFRA")
op.create_table(
'container_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('record', sa.String(), nullable=True),
sa.Column('container_name', sa.String(), nullable=True),
sa.Column('create_ts', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.PrimaryKeyConstraint('id'),
schema='STG_INFRA',
)
op.create_group(
"test_dwh_stg_infra_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_read"
)
op.create_group(
"test_dwh_stg_infra_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_write"
)
op.create_group("test_dwh_stg_infra_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_all")
op.grant_on_schema(
"test_dwh_stg_infra_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_read",
"STG_INFRA",
)
op.grant_on_schema(
"test_dwh_stg_infra_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_write",
"STG_INFRA",
)
op.grant_on_schema(
"test_dwh_stg_infra_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_all", "STG_INFRA"
)
op.grant_on_table(
"test_dwh_stg_infra_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_read",
['SELECT'],
'"STG_INFRA".container_log',
)
op.grant_on_table(
"test_dwh_stg_infra_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_write",
['SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'INSERT'],
'"STG_INFRA".container_log',
)
op.grant_on_table(
"test_dwh_stg_infra_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_all",
['ALL'],
'"STG_INFRA".container_log',
)

# Old
op.alter_column('union_member', 'card_user', existing_type=sa.VARCHAR(), nullable=True, schema='STG_UNION_MEMBER')


def downgrade():
op.drop_table('container_log', schema='STG_INFRA')
op.delete_group("test_dwh_stg_infra_all" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_all")
op.delete_group(
"test_dwh_stg_infra_write" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_write"
)
op.delete_group(
"test_dwh_stg_infra_read" if os.getenv("ENVIRONMENT") != "production" else "prod_dwh_stg_infra_read"
)
op.drop_table_schema("STG_INFRA")

# Old
op.alter_column('union_member', 'card_user', existing_type=sa.VARCHAR(), nullable=False, schema='STG_UNION_MEMBER')
15 changes: 15 additions & 0 deletions profcomff_definitions/STG/infra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from datetime import UTC, datetime

import sqlalchemy as sa
from sqlalchemy.orm import Mapped, mapped_column

from profcomff_definitions.base import Base


class ContainerLog(Base):
id: Mapped[int] = mapped_column(primary_key=True)
record: Mapped[str | None]
container_name: Mapped[str | None]
create_ts: Mapped[datetime | None] = mapped_column(
server_default=sa.text("now()"), default=lambda: datetime.now(UTC)
)
2 changes: 1 addition & 1 deletion profcomff_definitions/STG/social.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Group(Base):
id: Mapped[int] = mapped_column(primary_key=True)
owner_id: Mapped[int | None]

name: Mapped[str | None]
description: Mapped[str | None]
invite_link: Mapped[str | None]
Expand Down
2 changes: 1 addition & 1 deletion profcomff_definitions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys


__version__ = '2024.05.05.2'
__version__ = '2024.05.07'


dir_path = os.path.dirname(os.path.abspath(__file__))
Expand Down

0 comments on commit 0db067c

Please sign in to comment.