Jun 26 MT-0 phase

This commit is contained in:
2026-06-26 16:19:48 -04:00
parent 5d95cdbbfc
commit fc39491891
13 changed files with 1094 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
"""
control/seed.py
---------------
Idempotent seeding of the baseline plans (upsert by `code`). Mirrors the
plan-tier matrix in MULTI_TENANT_PLAN.md §6. Safe to re-run — re-running
updates existing plan rows in place rather than creating duplicates.
"""
from control.base import control_session
from control.models import Plan
PLAN_DEFS = [
dict(code='free', name='Free',
max_users=3, max_facilities=2,
max_inspections_month=50, max_issues_month=50,
allow_custom_domain=False, allow_mobile_api=False,
allow_scheduled_reports=False, allow_branding=False,
price_cents=0, billing_period='month'),
dict(code='starter', name='Starter',
max_users=15, max_facilities=10,
max_inspections_month=500, max_issues_month=500,
allow_custom_domain=False, allow_mobile_api=True,
allow_scheduled_reports=False, allow_branding=False,
price_cents=None, billing_period='month'),
dict(code='pro', name='Pro',
max_users=50, max_facilities=50,
max_inspections_month=5000, max_issues_month=5000,
allow_custom_domain=True, allow_mobile_api=True,
allow_scheduled_reports=True, allow_branding=True,
price_cents=None, billing_period='month'),
dict(code='enterprise', name='Enterprise',
max_users=None, max_facilities=None,
max_inspections_month=None, max_issues_month=None,
allow_custom_domain=True, allow_mobile_api=True,
allow_scheduled_reports=True, allow_branding=True,
price_cents=None, billing_period='month'),
]
def seed_plans():
"""Upsert baseline plans. Returns (created_count, updated_count)."""
created, updated = 0, 0
with control_session() as s:
for d in PLAN_DEFS:
plan = s.query(Plan).filter_by(code=d['code']).first()
if plan is None:
s.add(Plan(**d))
created += 1
else:
for k, v in d.items():
setattr(plan, k, v)
updated += 1
return created, updated
if __name__ == '__main__':
c, u = seed_plans()
print(f'Plans seeded — created={c} updated={u}')