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

113 lines
4.3 KiB
Python

# Generated by Django 5.2.17 on 2026-09-24 14:10
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
("auth", "0012_alter_user_first_name_max_length"),
("tenancy", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="FeatureFlag",
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)),
("description", models.TextField(blank=True)),
("is_active", models.BooleanField(default=False)),
(
"rollout_percentage",
models.PositiveSmallIntegerField(default=100, help_text="0-100. 100 = all users"),
),
("environments", models.JSONField(default=list, help_text='["production", "staging"] or [] = all')),
("category", models.CharField(blank=True, help_text="Grouping for UI", max_length=50)),
("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": "features_flag",
},
),
migrations.CreateModel(
name="FeatureFlagOverride",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("is_enabled", models.BooleanField()),
(
"flag",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="overrides",
to="infrasynth_features.featureflag",
),
),
(
"group",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="auth.group",
),
),
(
"tenant",
models.ForeignKey(
editable=False,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="tenancy.tenant",
),
),
(
"user",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"db_table": "features_override",
},
),
migrations.AddConstraint(
model_name="featureflag",
constraint=models.UniqueConstraint(fields=("tenant", "slug"), name="uniq_feature_flag_slug_per_tenant"),
),
migrations.AddConstraint(
model_name="featureflag",
constraint=models.UniqueConstraint(
condition=models.Q(("tenant__isnull", True)), fields=("slug",), name="uniq_global_feature_flag_slug"
),
),
migrations.AddConstraint(
model_name="featureflagoverride",
constraint=models.UniqueConstraint(fields=("flag", "user"), name="uniq_override_flag_user"),
),
migrations.AddConstraint(
model_name="featureflagoverride",
constraint=models.UniqueConstraint(fields=("flag", "group"), name="uniq_override_flag_group"),
),
]