infrasynth-backend-kit/infrasynth/notifications/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

141 lines
5.8 KiB
Python

# Generated by Django 5.2.17 on 2026-09-24 14:10
import django.db.models.deletion
from django.db import migrations, models
import infrasynth.shared.enums
class Migration(migrations.Migration):
initial = True
dependencies = [
("tenancy", "0001_initial"),
]
operations = [
migrations.CreateModel(
name="NotificationTemplate",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("slug", models.SlugField(max_length=100)),
("name", models.CharField(max_length=200)),
("channel", models.CharField(choices=infrasynth.shared.enums.ChannelType.choices, max_length=20)),
("subject_template", models.CharField(max_length=500)),
("body_template", models.TextField()),
("is_html", models.BooleanField(default=False)),
("namespace", models.CharField(blank=True, default="", max_length=100)),
("metadata", models.JSONField(default=dict)),
(
"tenant",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="tenancy.tenant",
),
),
],
options={
"db_table": "notifications_template",
},
),
migrations.CreateModel(
name="NotificationDispatch",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("recipient", models.CharField(max_length=255)),
("channel", models.CharField(choices=infrasynth.shared.enums.ChannelType.choices, max_length=20)),
("subject", models.CharField(max_length=500)),
("body", models.TextField()),
(
"status",
models.CharField(
choices=[
("pending", "Pending"),
("sent", "Sent"),
("failed", "Failed"),
("retrying", "Retrying"),
],
default="pending",
max_length=20,
),
),
("error_message", models.TextField(blank=True, default="")),
("attempt", models.PositiveSmallIntegerField(default=0)),
("next_retry_at", models.DateTimeField(blank=True, null=True)),
("context_snapshot", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True)),
("completed_at", models.DateTimeField(blank=True, null=True)),
("request_id", models.UUIDField(blank=True, null=True)),
(
"tenant",
models.ForeignKey(
editable=False,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="tenancy.tenant",
),
),
(
"template",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="dispatches",
to="infrasynth_notifications.notificationtemplate",
),
),
],
options={
"db_table": "notifications_dispatch",
},
),
migrations.CreateModel(
name="ChannelConfig",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("slug", models.SlugField(max_length=100)),
("channel_type", models.CharField(choices=infrasynth.shared.enums.ChannelType.choices, max_length=20)),
("display_name", models.CharField(max_length=200)),
("config", models.JSONField(default=dict)),
("is_active", models.BooleanField(default=True)),
("priority", models.PositiveSmallIntegerField(default=0)),
(
"tenant",
models.ForeignKey(
editable=False,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="tenancy.tenant",
),
),
],
options={
"db_table": "notifications_channel_config",
"constraints": [
models.UniqueConstraint(fields=("tenant", "slug"), name="uniq_channel_config_slug_per_tenant")
],
},
),
migrations.AddConstraint(
model_name="notificationtemplate",
constraint=models.UniqueConstraint(
fields=("tenant", "slug", "namespace"), name="uniq_template_slug_namespace_per_tenant"
),
),
migrations.AddConstraint(
model_name="notificationtemplate",
constraint=models.UniqueConstraint(
condition=models.Q(("tenant__isnull", True)),
fields=("slug", "namespace"),
name="uniq_global_template_slug_namespace",
),
),
migrations.AddIndex(
model_name="notificationdispatch",
index=models.Index(fields=["tenant_id", "status"], name="notificatio_tenant__a73911_idx"),
),
]