Files
Juan DenisandClaude Fable 5 5417c39100 perf(models): index every foreign-key column
An audit found 102 FK columns with no index — every join, per-parent
listing, and the delete cascades from _delete_cascade_policy scanned
whole tables on them (deployments.app_id, audit_logs.user_id,
dns_records.zone_id, webhook_logs.webhook_id, ...). All FK columns now
declare index=True; migration 096 creates the same indexes on existing
installs, deriving the list from the live schema at upgrade time (so
it is idempotent and cannot drift from what an install actually has).

Ratchet: test_every_fk_column_is_indexed pins the rule with no
allowlist — a new FK column is born indexed or the build fails.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-31 20:42:53 -04:00

41 lines
1.6 KiB
Python

from datetime import datetime
from app import db
from app.models.mixins import TimestampMixin
class CloudflareWorker(TimestampMixin, db.Model):
"""A Cloudflare Worker (edge script) ServerKit uploaded.
Cloudflare is the source of truth for what's deployed; this table records the
source we pushed (so it can be viewed and re-deployed) and which connection it
belongs to. Keyed by ``(account_id, name)`` — a script name is unique per
account.
"""
__tablename__ = 'cloudflare_workers'
__table_args__ = (
db.UniqueConstraint('account_id', 'name', name='uq_cf_worker_account_name'),
)
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128), nullable=False, index=True) # script name
account_id = db.Column(db.String(64), nullable=False)
dns_provider_config_id = db.Column(
db.Integer, db.ForeignKey('dns_provider_configs.id'), nullable=True, index=True)
source = db.Column(db.Text) # JS module we uploaded
compatibility_date = db.Column(db.String(20))
def to_dict(self, include_source=False):
d = {
'id': self.id,
'name': self.name,
'account_id': self.account_id,
'dns_provider_config_id': self.dns_provider_config_id,
'compatibility_date': self.compatibility_date,
'created_at': self.created_at.isoformat() if self.created_at else None,
'updated_at': self.updated_at.isoformat() if self.updated_at else None,
}
if include_source:
d['source'] = self.source
return d