fixed sort time

This commit is contained in:
HotSwapp
2025-10-14 07:56:13 -05:00
parent 9b2ce0d28f
commit 65e4995a5b
26 changed files with 99601 additions and 28 deletions

View File

@@ -147,6 +147,37 @@ def create_tables() -> None:
# Handle case where auth module isn't available yet during initial import
pass
# Create helpful SQLite indexes for rolodex sorting if they do not exist
try:
if "sqlite" in DATABASE_URL:
index_ddls = [
# Name sort: NULLS LAST emulation terms first then values
"CREATE INDEX IF NOT EXISTS ix_clients_name_sort ON clients((last_name IS NULL), last_name, (first_name IS NULL), first_name)",
# Company/address/city/state/zip
"CREATE INDEX IF NOT EXISTS ix_clients_company_sort ON clients((company IS NULL), company)",
"CREATE INDEX IF NOT EXISTS ix_clients_address_sort ON clients((address IS NULL), address)",
"CREATE INDEX IF NOT EXISTS ix_clients_city_sort ON clients((city IS NULL), city)",
"CREATE INDEX IF NOT EXISTS ix_clients_state_sort ON clients((state IS NULL), state)",
"CREATE INDEX IF NOT EXISTS ix_clients_zip_sort ON clients((zip_code IS NULL), zip_code)",
# Updated sort via COALESCE(updated_at, created_at)
"CREATE INDEX IF NOT EXISTS ix_clients_updated_sort ON clients(COALESCE(updated_at, created_at))",
# Phone MIN(phone_number) correlated subquery helper
"CREATE INDEX IF NOT EXISTS ix_phones_client_phone ON phones(client_id, phone_number)",
]
with engine.begin() as conn:
for ddl in index_ddls:
conn.execute(text(ddl))
except Exception as e:
try:
from .logging_config import setup_logging
import structlog
setup_logging()
_logger = structlog.get_logger(__name__)
_logger.warning("sqlite_index_creation_failed", error=str(e))
except Exception:
pass
def get_database_url() -> str:
"""