forked from FOSS/AutoShop-Djimbo
refactor: remove Alembic migrations and Discord integration
This commit is contained in:
@@ -13,14 +13,17 @@ from tgbot.utils.const_functions import get_unix
|
||||
class PositionModel(Base):
|
||||
__tablename__ = "storage_position"
|
||||
|
||||
increment: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
increment: Mapped[int] = mapped_column(
|
||||
Integer, primary_key=True, autoincrement=True
|
||||
)
|
||||
category_id: Mapped[int] = mapped_column(BigInteger, nullable=False, index=True)
|
||||
position_id: Mapped[int] = mapped_column(BigInteger, nullable=False, index=True)
|
||||
position_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
position_price: Mapped[float] = mapped_column(Float, nullable=False, default=0)
|
||||
position_desc: Mapped[str] = mapped_column(Text, nullable=False, default="None")
|
||||
position_photo: Mapped[str] = mapped_column(Text, nullable=False, default="None")
|
||||
position_unix: Mapped[int] = mapped_column(Integer, nullable=False, default=get_unix)
|
||||
position_unix: Mapped[int] = mapped_column(
|
||||
Integer, nullable=False, default=get_unix
|
||||
)
|
||||
|
||||
|
||||
ModelBase = Position
|
||||
@@ -37,13 +40,12 @@ class Positionx(BaseRepository[PositionModel, Position]):
|
||||
|
||||
# Добавление позиции товара
|
||||
async def add(
|
||||
self,
|
||||
category_id: int,
|
||||
position_id: int,
|
||||
position_name: str,
|
||||
position_price: float,
|
||||
position_desc: str,
|
||||
position_photo: str,
|
||||
self,
|
||||
category_id: int,
|
||||
position_id: int,
|
||||
position_name: str,
|
||||
position_price: float,
|
||||
position_desc: str,
|
||||
) -> Position:
|
||||
return await self._insert(
|
||||
category_id=category_id,
|
||||
@@ -51,12 +53,13 @@ class Positionx(BaseRepository[PositionModel, Position]):
|
||||
position_name=position_name,
|
||||
position_price=position_price,
|
||||
position_desc=position_desc,
|
||||
position_photo=position_photo,
|
||||
position_unix=get_unix(),
|
||||
)
|
||||
|
||||
# Обновление позиции по ID или фильтру
|
||||
async def update(self, where: Optional[Union[Dict[str, Any], int]] = None, **kwargs) -> int:
|
||||
async def update(
|
||||
self, where: Optional[Union[Dict[str, Any], int]] = None, **kwargs
|
||||
) -> int:
|
||||
if isinstance(where, int):
|
||||
where = {"position_id": where}
|
||||
|
||||
@@ -68,12 +71,15 @@ class Positionx(BaseRepository[PositionModel, Position]):
|
||||
from tgbot.database.db_item import ItemModel
|
||||
|
||||
item_table = ItemModel.__table__
|
||||
statement = (
|
||||
select(item_table.c.position_id, func.count(item_table.c.increment).label("item_count"))
|
||||
.group_by(item_table.c.position_id)
|
||||
)
|
||||
statement = select(
|
||||
item_table.c.position_id,
|
||||
func.count(item_table.c.increment).label("item_count"),
|
||||
).group_by(item_table.c.position_id)
|
||||
|
||||
async with session_scope() as session:
|
||||
rows = await session.execute(statement)
|
||||
|
||||
return {int(position_id): int(item_count) for position_id, item_count in rows.all()}
|
||||
return {
|
||||
int(position_id): int(item_count)
|
||||
for position_id, item_count in rows.all()
|
||||
}
|
||||
|
||||
@@ -14,20 +14,34 @@ class SettingsModel(Base):
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, default=1)
|
||||
status_work: Mapped[str] = mapped_column(String(16), nullable=False, default="True")
|
||||
status_refill: Mapped[str] = mapped_column(String(16), nullable=False, default="False")
|
||||
status_refill: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="False"
|
||||
)
|
||||
status_buy: Mapped[str] = mapped_column(String(16), nullable=False, default="False")
|
||||
notification_refill: Mapped[str] = mapped_column(String(16), nullable=False, default="True")
|
||||
notification_buy: Mapped[str] = mapped_column(String(16), nullable=False, default="False")
|
||||
notification_refill: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="True"
|
||||
)
|
||||
notification_buy: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="False"
|
||||
)
|
||||
misc_faq: Mapped[str] = mapped_column(String, nullable=False, default="None")
|
||||
misc_support: Mapped[str] = mapped_column(String, nullable=False, default="None")
|
||||
misc_bot: Mapped[str] = mapped_column(String(255), nullable=False, default="None")
|
||||
misc_hosting_text: Mapped[str] = mapped_column(String(64), nullable=False, default="telegraph")
|
||||
misc_token_telegraph: Mapped[str] = mapped_column(String, nullable=False, default="None")
|
||||
misc_discord_webhook_url: Mapped[str] = mapped_column(String, nullable=False, default="None")
|
||||
misc_discord_webhook_name: Mapped[str] = mapped_column(String(255), nullable=False, default="None")
|
||||
misc_hide_category: Mapped[str] = mapped_column(String(16), nullable=False, default="False")
|
||||
misc_hide_position: Mapped[str] = mapped_column(String(16), nullable=False, default="False")
|
||||
misc_method_prod: Mapped[str] = mapped_column(String(16), nullable=False, default="skip")
|
||||
misc_hosting_text: Mapped[str] = mapped_column(
|
||||
String(64), nullable=False, default="telegraph"
|
||||
)
|
||||
misc_token_telegraph: Mapped[str] = mapped_column(
|
||||
String, nullable=False, default="None"
|
||||
)
|
||||
misc_hide_category: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="False"
|
||||
)
|
||||
misc_hide_position: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="False"
|
||||
)
|
||||
misc_method_prod: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default="skip"
|
||||
)
|
||||
misc_profit_day: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
misc_profit_week: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
misc_profit_month: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
|
||||
@@ -18,7 +18,6 @@ class Position:
|
||||
position_name: str
|
||||
position_price: float
|
||||
position_desc: str
|
||||
position_photo: str
|
||||
position_unix: int
|
||||
|
||||
|
||||
@@ -86,8 +85,6 @@ class Settings:
|
||||
misc_bot: str
|
||||
misc_hosting_text: str
|
||||
misc_token_telegraph: str
|
||||
misc_discord_webhook_url: str
|
||||
misc_discord_webhook_name: str
|
||||
misc_hide_category: str
|
||||
misc_hide_position: str
|
||||
misc_method_prod: str
|
||||
|
||||
@@ -12,13 +12,11 @@ from tgbot.database.core import database_url
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||||
ALEMBIC_INI = PROJECT_ROOT / "alembic.ini"
|
||||
MIGRATIONS_DIR = PROJECT_ROOT / "migrations"
|
||||
|
||||
|
||||
# Сбор Alembic-конфига от корня проекта
|
||||
def get_alembic_config(url: str = database_url) -> Config:
|
||||
config = Config(str(ALEMBIC_INI))
|
||||
config.set_main_option("script_location", str(MIGRATIONS_DIR))
|
||||
config.set_main_option("sqlalchemy.url", url)
|
||||
|
||||
return config
|
||||
|
||||
@@ -6,7 +6,6 @@ from sqlalchemy import delete as sqlalchemy_delete
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import update as sqlalchemy_update
|
||||
from tgbot.database.core import Base, database_path, session_scope
|
||||
from tgbot.database.migration_runner import run_migrations
|
||||
from tgbot.utils.misc.bot_logging import bot_logger
|
||||
|
||||
ModelTranslator = TypeVar("ModelTranslator", bound=Base)
|
||||
@@ -151,7 +150,7 @@ class BaseRepository(Generic[ModelTranslator, EntityTranslator]):
|
||||
# Применение миграций и создание дефолтных строк
|
||||
async def prepare_database() -> None:
|
||||
database_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
await run_migrations()
|
||||
# await run_migrations()
|
||||
|
||||
from tgbot.database.db_payments import Paymentsx
|
||||
from tgbot.database.db_settings import Settingsx
|
||||
|
||||
Reference in New Issue
Block a user