mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-10-19 23:01:29 +02:00
SQLModel emitted index=True beside primary_key=True on every id field, so 41 tables carried ix_<table>_id alongside <table>_pkey: the same single-column btree twice. 12 MB of duplicate index, and every insert maintaining both — on the hot path of a scan writing 345,152 endpoints. The planner had been using them (72,160 scans across the set) simply because they were there and equivalent; with them gone it uses the primary key, verified on subdomains: Index Scan using subdomains_pkey. The migration finds them rather than naming them, because which tables exist depends on how far an install has migrated and a name already gone must not fail an upgrade. It drops only a non-unique, single-column btree on id belonging to a table that has a primary key — no other index can match that shape. There is no downgrade: the primary key serves every lookup they served. The 33 models are corrected too, so the next hand-written migration is not comparing against a schema that would want them back. Counted honestly: 41, not the 102 an earlier pass reported — that number included the 61 primary keys themselves. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013dKUV96WkQQETZBMoAG98C
27 lines
908 B
Python
27 lines
908 B
Python
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import Column
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlmodel import Field, SQLModel, UniqueConstraint
|
|
|
|
from shared.utils.datetime import utc_now
|
|
|
|
|
|
class ViewDNSCache(SQLModel, table=True):
|
|
__tablename__ = "viewdns_cache"
|
|
__table_args__ = (
|
|
UniqueConstraint("lookup_type", "query_value", name="uq_viewdns_cache_lookup"),
|
|
)
|
|
|
|
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
|
|
lookup_type: str = Field(index=True)
|
|
query_value: str = Field(index=True)
|
|
result_count: int = Field(default=0)
|
|
response_data: dict = Field(
|
|
default_factory=dict, sa_column=Column(JSONB, nullable=False, default={})
|
|
)
|
|
queried_at: datetime = Field(default_factory=utc_now)
|
|
created_at: datetime = Field(default_factory=utc_now)
|
|
updated_at: datetime = Field(default_factory=utc_now)
|