infrasynth-backend-kit/infrasynth/tenancy/migrations/0001_initial.py
jcv-dev 551b42eab5 feat: production-hardening pass across the kit
Close the gaps between the documented contract (API-STANDARD, TENANCY,
ENTITLEMENTS) and the implementation, and remove committed build artifacts.

Security:
- verify + process inbound webhooks (HMAC/handler verify, size limit,
  timestamp tolerance, idempotency via InboundEvent.external_id)
- real 2FA login flow (pre-auth challenge; tokens only after verify/recovery)
- wire HybridPermission into security/audit views; add API-key rotate and
  users/<id>/permissions|roles endpoints
- tenant-scoped throttling on by default; webhook replay protection
- verify MercadoPago webhook signatures
- login brute-force guard, configurable password policy, real ALTCHA PoW

Correctness:
- apply verified billing webhooks idempotently (subscription/entitlement/
  invoice/PaymentTransaction); scheduled payment lifecycle jobs
- capture audit update diffs automatically; add audit retention purge
- working notification retries, per-channel rate limits, log retention
- pluggable virus scanner, upload-size limit, pipeline toggle
- feature rollout %/environment targeting; settings-driven registrations
- workflow guards (instance cap, route depth, self-assignment, clone on re-entry)
- wire every previously-dead INFRASYNTH_* setting; drop truly dead ones

Delivery:
- README + CHANGELOG; CI format check + coverage gate
- keep test media out of the tree; untrack .coverage, __pycache__,
  egg-info, docs/ and invoice artifacts
2026-09-24 10:41:21 -05:00

131 lines
5.3 KiB
Python

# Generated by Django 5.2.17 on 2026-09-24 14:10
import uuid
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="Tenant",
fields=[
("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
("slug", models.SlugField(max_length=100, unique=True)),
("name", models.CharField(max_length=200)),
(
"status",
models.CharField(
choices=[
("trialing", "Trialing"),
("active", "Active"),
("suspended", "Suspended"),
("archived", "Archived"),
],
default="active",
max_length=20,
),
),
("locale", models.CharField(default="es", max_length=10)),
("timezone", models.CharField(default="UTC", max_length=64)),
("metadata", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True)),
("suspended_at", models.DateTimeField(blank=True, null=True)),
("archived_at", models.DateTimeField(blank=True, null=True)),
],
options={
"db_table": "tenancy_tenant",
},
),
migrations.CreateModel(
name="PlatformStaff",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("reason", models.TextField(blank=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="platform_staff",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"db_table": "tenancy_platform_staff",
},
),
migrations.CreateModel(
name="TenantInvitation",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("email", models.EmailField(max_length=254)),
("role", models.CharField(default="member", max_length=50)),
("token", models.CharField(max_length=64, unique=True)),
("expires_at", models.DateTimeField()),
("accepted_at", models.DateTimeField(blank=True, null=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
(
"invited_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"tenant",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="invitations", to="tenancy.tenant"
),
),
],
options={
"db_table": "tenancy_invitation",
"indexes": [
models.Index(fields=["tenant", "email"], name="tenancy_inv_tenant__5dfb1c_idx"),
models.Index(fields=["tenant", "token"], name="tenancy_inv_tenant__f9fed9_idx"),
],
},
),
migrations.CreateModel(
name="TenantMembership",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("role", models.CharField(default="member", max_length=50)),
("is_owner", models.BooleanField(default=False)),
("is_active", models.BooleanField(default=True)),
("joined_at", models.DateTimeField(auto_now_add=True)),
(
"tenant",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="memberships", to="tenancy.tenant"
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="tenant_memberships",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"db_table": "tenancy_membership",
"indexes": [models.Index(fields=["user", "is_active"], name="tenancy_mem_user_id_4a284b_idx")],
"unique_together": {("tenant", "user")},
},
),
]