feat: переезд на tortose

This commit is contained in:
Artem Tsyrulnikov
2025-12-11 09:17:31 +03:00
parent 2af23f84fe
commit 0f0de396e1
16 changed files with 437 additions and 611 deletions

View File

@@ -1,31 +1,26 @@
import uuid
from typing import TYPE_CHECKING
from sqlalchemy import BigInteger, Column, ForeignKey, Table
from sqlalchemy.orm import Mapped, mapped_column, relationship
from src import domain
if TYPE_CHECKING:
from . import TargetChannel
target_external_channel = Table(
'target_external_channel',
domain.Base.metadata,
Column('target_channel_id', ForeignKey('target_channel.id', ondelete='CASCADE'), primary_key=True),
Column('external_channel_id', ForeignKey('external_channel.id', ondelete='CASCADE'), primary_key=True),
)
from tortoise import fields
from tortoise.models import Model
class ExternalChannel(domain.Base):
telegram_id: Mapped[int] = mapped_column(BigInteger, unique=True, index=True)
title: Mapped[str]
username: Mapped[str | None] = mapped_column(index=True)
description: Mapped[str | None]
subscribers_count: Mapped[int | None]
user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey('user.id'), index=True)
class ExternalChannel(Model):
id = fields.UUIDField(pk=True)
telegram_id = fields.BigIntField(unique=True, index=True)
title = fields.CharField(max_length=255)
username = fields.CharField(max_length=255, null=True, index=True)
description = fields.TextField(null=True)
subscribers_count = fields.IntField(null=True)
target_channels: Mapped[list['TargetChannel']] = relationship(
secondary=target_external_channel,
back_populates='external_channels',
)
user = fields.ForeignKeyField('models.User', related_name='external_channels', on_delete=fields.CASCADE, index=True)
created_at = fields.DatetimeField(auto_now_add=True)
updated_at = fields.DatetimeField(auto_now=True)
deleted_at = fields.DatetimeField(null=True)
# Many-to-many с TargetChannel (определено в TargetChannel)
# target_channels: fields.ManyToManyRelation['TargetChannel']
# Reverse relations:
# placements: fields.ReverseRelation['Placement']
class Meta:
table = 'external_channel'