-
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.
## Изменения - Группы выделены в отдельную сущность и созданы подтипы для групп тг/вк - Добавлен create_ts для вебхук стоража - Группы тг теперь создаются автоматически
- Loading branch information
Showing
21 changed files
with
377 additions
and
73 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Python tests | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
name: Unit tests | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: postgres:15 | ||
env: | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
-p 5432:5432 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" | ||
- name: Install dependencies | ||
run: | | ||
python -m ensurepip | ||
python -m pip install --upgrade pip | ||
pip install --upgrade -r requirements.txt -r requirements.dev.txt | ||
- name: Migrate DB | ||
run: | | ||
DB_DSN=postgresql://postgres@localhost:5432/postgres alembic upgrade head | ||
- name: Build coverage file | ||
id: pytest | ||
run: | | ||
DB_DSN=postgresql://postgres@localhost:5432/postgres pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=services_backend tests/ | tee pytest-coverage.txt | ||
exit ${PIPESTATUS[0]} | ||
- name: Print report | ||
if: always() | ||
run: | | ||
cat pytest-coverage.txt | ||
- name: Pytest coverage comment | ||
uses: MishaKav/pytest-coverage-comment@main | ||
with: | ||
pytest-coverage-path: ./pytest-coverage.txt | ||
title: Coverage Report | ||
badge-title: Code Coverage | ||
hide-badge: false | ||
hide-report: false | ||
create-new-comment: false | ||
hide-comment: false | ||
report-only-changed-files: false | ||
remove-link-from-badge: false | ||
junitxml-path: ./pytest.xml | ||
junitxml-title: Summary | ||
- name: Fail on pytest errors | ||
if: steps.pytest.outcome == 'failure' | ||
run: exit 1 | ||
|
||
linting: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.11 | ||
- uses: isort/isort-action@master | ||
with: | ||
requirementsFiles: "requirements.txt requirements.dev.txt" | ||
- uses: psf/black@stable | ||
- name: Comment if linting failed | ||
if: failure() | ||
uses: thollander/actions-comment-pull-request@v2 | ||
with: | ||
message: | | ||
:poop: Code linting failed, use `black` and `isort` to fix it. |
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
101 changes: 101 additions & 0 deletions
101
migrations/versions/1cacaf803a1d_user_defined_groups.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,101 @@ | ||
"""User defined groups | ||
Revision ID: 1cacaf803a1d | ||
Revises: 9d98c1e9c864 | ||
Create Date: 2024-04-14 23:38:18.956845 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.schema import CreateSequence, Sequence | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '1cacaf803a1d' | ||
down_revision = '9d98c1e9c864' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
'group', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('type', sa.String(), nullable=False), | ||
sa.Column('owner_id', sa.Integer(), nullable=True), | ||
sa.Column('is_deleted', sa.Boolean(), nullable=False), | ||
sa.Column('last_active_ts', sa.DateTime(), nullable=False), | ||
sa.Column('create_ts', sa.DateTime(), nullable=False), | ||
sa.Column('update_ts', sa.DateTime(), nullable=False), | ||
) | ||
op.execute( | ||
''' | ||
INSERT INTO "group" | ||
(id, type, is_deleted, last_active_ts, create_ts, update_ts) | ||
SELECT id, 'vk_group', False, now(), create_ts, update_ts | ||
FROM vk_groups; | ||
''' | ||
) | ||
|
||
max_id = op.get_bind().execute(sa.text('SELECT MAX(id) FROM "group";')).scalar() or 0 | ||
op.create_primary_key('group_pk', 'group', ['id']) | ||
op.execute(CreateSequence(Sequence('group_id_seq', max_id + 1))) | ||
op.alter_column('group', 'id', server_default=sa.text('nextval(\'group_id_seq\')')) | ||
|
||
op.create_table( | ||
'telegram_channel', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('channel_id', sa.BigInteger(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
['id'], | ||
['group.id'], | ||
), | ||
sa.PrimaryKeyConstraint('id'), | ||
) | ||
op.create_table( | ||
'telegram_chat', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('chat_id', sa.BigInteger(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
['id'], | ||
['group.id'], | ||
), | ||
sa.PrimaryKeyConstraint('id'), | ||
) | ||
op.create_table( | ||
'vk_chat', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('peer_id', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
['id'], | ||
['group.id'], | ||
), | ||
sa.PrimaryKeyConstraint('id'), | ||
) | ||
op.create_foreign_key('group_vkgroup_fk', 'vk_groups', 'group', ['id'], ['id']) | ||
op.drop_column('vk_groups', 'update_ts') | ||
op.drop_column('vk_groups', 'create_ts') | ||
op.execute('DROP SEQUENCE IF EXISTS vk_groups_id_seq CASCADE;') | ||
op.rename_table('vk_groups', 'vk_group') | ||
|
||
|
||
def downgrade(): | ||
op.rename_table('vk_group', 'vk_groups') | ||
|
||
max_id = op.get_bind().execute(sa.text('SELECT MAX(id) FROM "vk_groups";')).scalar() or 0 | ||
op.execute(CreateSequence(Sequence('vk_groups_id_seq', max_id + 1))) | ||
op.alter_column('vk_groups', 'id', server_default=sa.text('nextval(\'vk_groups_id_seq\')')) | ||
|
||
op.add_column('vk_groups', sa.Column('create_ts', sa.DateTime())) | ||
op.add_column('vk_groups', sa.Column('update_ts', sa.DateTime())) | ||
op.execute('UPDATE vk_groups SET create_ts = (SELECT create_ts FROM "group" WHERE "group".id = vk_groups.id);') | ||
op.execute('UPDATE vk_groups SET update_ts = (SELECT update_ts FROM "group" WHERE "group".id = vk_groups.id);') | ||
op.alter_column('vk_groups', 'create_ts', nullable=False) | ||
op.alter_column('vk_groups', 'update_ts', nullable=False) | ||
op.drop_constraint('group_vkgroup_fk', 'vk_groups', type_='foreignkey') | ||
op.drop_table('vk_chat') | ||
op.drop_table('telegram_chat') | ||
op.drop_table('telegram_channel') | ||
op.drop_table('group') | ||
op.execute('DROP SEQUENCE IF EXISTS group_id_seq CASCADE;') |
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: 2023-03-12 14:22:34.958257 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
|
25 changes: 25 additions & 0 deletions
25
migrations/versions/62addefd9655_webhookstorage_event_ts.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,25 @@ | ||
"""WebhookStorage event_ts | ||
Revision ID: 62addefd9655 | ||
Revises: 1cacaf803a1d | ||
Create Date: 2024-04-15 00:21:54.075449 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '62addefd9655' | ||
down_revision = '1cacaf803a1d' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.add_column('webhook_storage', sa.Column('event_ts', sa.DateTime(), nullable=True)) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column('webhook_storage', 'event_ts') |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import logging | ||
from collections.abc import Callable | ||
|
||
from social.utils.events import EventProcessor | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import logging | ||
from collections.abc import Callable | ||
|
||
from social.utils.events import EventProcessor | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from .vk import VkGroups | ||
from .group import TelegramChannel, TelegramChat, VkChat, VkGroup | ||
from .webhook_storage import WebhookStorage | ||
|
||
|
||
__all__ = ['WebhookStorage', 'VkGroups'] | ||
__all__ = ['WebhookStorage', 'TelegramChannel', 'TelegramChat', 'VkGroup', 'VkChat'] |
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,60 @@ | ||
from datetime import UTC, datetime | ||
|
||
import sqlalchemy as sa | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
from .base import Base | ||
|
||
|
||
class Group(Base): | ||
id: Mapped[int] = mapped_column(primary_key=True) | ||
type: Mapped[str] | ||
owner_id: Mapped[int | None] | ||
|
||
is_deleted: Mapped[bool] = mapped_column(default=False) | ||
last_active_ts: Mapped[datetime | None] | ||
|
||
create_ts: Mapped[datetime] = mapped_column(default=lambda: datetime.now(UTC)) | ||
update_ts: Mapped[datetime] = mapped_column(default=lambda: datetime.now(UTC), onupdate=lambda: datetime.now(UTC)) | ||
|
||
__mapper_args__ = { | ||
"polymorphic_on": "type", | ||
} | ||
|
||
|
||
class VkGroup(Group): | ||
id: Mapped[int] = mapped_column(sa.ForeignKey("group.id"), primary_key=True) | ||
group_id: Mapped[int] | ||
confirmation_token: Mapped[str] | ||
secret_key: Mapped[str] | ||
|
||
__mapper_args__ = { | ||
"polymorphic_identity": "vk_group", | ||
} | ||
|
||
|
||
class VkChat(Group): | ||
id: Mapped[int] = mapped_column(sa.ForeignKey("group.id"), primary_key=True) | ||
peer_id: Mapped[int] | ||
|
||
__mapper_args__ = { | ||
"polymorphic_identity": "vk_chat", | ||
} | ||
|
||
|
||
class TelegramChannel(Group): | ||
id: Mapped[int] = mapped_column(sa.ForeignKey("group.id"), primary_key=True) | ||
channel_id: Mapped[int] | ||
|
||
__mapper_args__ = { | ||
"polymorphic_identity": "tg_channel", | ||
} | ||
|
||
|
||
class TelegramChat(Group): | ||
id: Mapped[int] = mapped_column(sa.ForeignKey("group.id"), primary_key=True) | ||
chat_id: Mapped[int] | ||
|
||
__mapper_args__ = { | ||
"polymorphic_identity": "tg_chat", | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.