improve docker compose setup
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Alembic env.py — подключение к БД через Settings."""
|
||||
# Alembic env.py — подключение к БД через Settings.
|
||||
|
||||
import os
|
||||
import sys
|
||||
@@ -27,7 +27,7 @@ target_metadata = Base.metadata
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
"""Run migrations in 'offline' mode."""
|
||||
# Run migrations in 'offline' mode.
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url,
|
||||
@@ -40,7 +40,7 @@ def run_migrations_offline() -> None:
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
"""Run migrations in 'online' mode."""
|
||||
# Run migrations in 'online' mode.
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
|
||||
47
alembic/versions/002_add_indexes.py
Normal file
47
alembic/versions/002_add_indexes.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""Add performance indexes for growing database
|
||||
|
||||
Revision ID: 002_add_indexes
|
||||
Revises: 001_initial
|
||||
Create Date: 2026-04-09
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "002_add_indexes"
|
||||
down_revision: Union[str, None] = "001_initial"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# cars: ускорение фильтрации по бренду в API и статистике
|
||||
op.create_index("ix_cars_brand", "cars", ["brand"])
|
||||
|
||||
# cars: составной индекс бренд+модель для комбинированных фильтров
|
||||
op.create_index("ix_cars_brand_model", "cars", ["brand", "model"])
|
||||
|
||||
# cars: ускорение фильтрации по году (year_min/year_max)
|
||||
op.create_index("ix_cars_year", "cars", ["year"])
|
||||
|
||||
# cars: ускорение фильтрации по статусу продажи
|
||||
op.create_index("ix_cars_is_sold", "cars", ["is_sold"])
|
||||
|
||||
# cars: ускорение сортировки ORDER BY last_seen_at DESC (пагинация)
|
||||
op.create_index("ix_cars_last_seen_at", "cars", ["last_seen_at"])
|
||||
|
||||
# images: ускорение JOIN/DELETE по car_id (критично при upsert)
|
||||
op.create_index("ix_images_car_id", "images", ["car_id"])
|
||||
|
||||
# sync_runs: ускорение поиска stale runs по статусу
|
||||
op.create_index("ix_sync_runs_status", "sync_runs", ["status"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_sync_runs_status", table_name="sync_runs")
|
||||
op.drop_index("ix_images_car_id", table_name="images")
|
||||
op.drop_index("ix_cars_last_seen_at", table_name="cars")
|
||||
op.drop_index("ix_cars_is_sold", table_name="cars")
|
||||
op.drop_index("ix_cars_year", table_name="cars")
|
||||
op.drop_index("ix_cars_brand_model", table_name="cars")
|
||||
op.drop_index("ix_cars_brand", table_name="cars")
|
||||
Reference in New Issue
Block a user