Files
Juan DenisandClaude Fable 5 96d162e9a4 feat(hosting): per-site nginx micro-cache toggle
Opt-in 10s FastCGI/proxy micro-cache per site (migration 053) with safe
bypasses for logged-in/admin/cart cookies and paths, X-SK-Cache header
for verification, and a shared-zone purge. Flows through the drift-safe
vhost render seam so detection and writes always agree.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 15:21:50 -04:00

46 lines
1.3 KiB
Python

"""Per-site micro-cache toggle (task #21).
Adds:
- applications.micro_cache_enabled (Boolean, nullable)
NULL/False = off (today's behavior). When enabled, the app's nginx vhost is
rendered with short-TTL fastcgi/proxy cache directives plus auth/admin/cart
bypasses (see NginxService._with_micro_cache).
Idempotent: MigrationService runs _fix_missing_columns() + db.create_all() on boot
before Alembic, so guard on the live schema.
Revision ID: 053_micro_cache
Revises: 052_site_bandwidth
Create Date: 2026-07-03
"""
from alembic import op
import sqlalchemy as sa
revision = '053_micro_cache'
down_revision = '052_site_bandwidth'
branch_labels = None
depends_on = None
_COLUMN = 'micro_cache_enabled'
def upgrade():
conn = op.get_bind()
inspector = sa.inspect(conn)
if 'applications' not in set(inspector.get_table_names()):
return
cols = {c['name'] for c in inspector.get_columns('applications')}
if _COLUMN not in cols:
op.add_column('applications', sa.Column(_COLUMN, sa.Boolean(), nullable=True))
def downgrade():
conn = op.get_bind()
inspector = sa.inspect(conn)
if 'applications' not in set(inspector.get_table_names()):
return
cols = {c['name'] for c in inspector.get_columns('applications')}
if _COLUMN in cols:
op.drop_column('applications', _COLUMN)