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

28 lines
1.2 KiB
Python

from datetime import datetime
from app import db
from app.models.mixins import TimestampMixin, SerializableMixin
class CloudflareTunnel(SerializableMixin, TimestampMixin, db.Model):
"""A Cloudflare Tunnel (cloudflared / cfd_tunnel) ServerKit created.
Distinct from the WireGuard remote-access ``Tunnel`` model — this is a
Cloudflare-managed tunnel that exposes a local service through Cloudflare's
edge. Records the connector token (encrypted at rest) so the install command
can be shown without re-fetching, and which connection owns it.
"""
__tablename__ = 'cloudflare_tunnels'
__table_args__ = (
db.UniqueConstraint('account_id', 'tunnel_id', name='uq_cf_tunnel_account_id'),
)
id = db.Column(db.Integer, primary_key=True)
tunnel_id = db.Column(db.String(64), nullable=False, index=True) # Cloudflare tunnel id
name = db.Column(db.String(128), nullable=False)
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)
token_encrypted = db.Column(db.Text) # cloudflared connector token (encrypted)