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

197 lines
7.7 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 = [
("tenancy", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="FileCategory",
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)),
("storage_path", models.CharField(max_length=500)),
("allowed_extensions", models.TextField(blank=True)),
("max_size_bytes", models.BigIntegerField(blank=True, null=True)),
("is_active", models.BooleanField(default=True)),
("storage_backend_override", models.CharField(blank=True, max_length=50)),
(
"tenant",
models.ForeignKey(
editable=False,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="tenancy.tenant",
),
),
],
options={
"db_table": "files_category",
},
),
migrations.CreateModel(
name="ProcessingPipeline",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("name", models.CharField(max_length=200)),
("slug", models.SlugField(max_length=100)),
("steps", models.JSONField()),
("is_active", models.BooleanField(default=True)),
(
"tenant",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="tenancy.tenant",
),
),
],
options={
"db_table": "files_pipeline",
},
),
migrations.CreateModel(
name="StoredFile",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("storage_backend", models.CharField(max_length=50)),
("storage_key", models.CharField(max_length=500)),
("original_filename", models.CharField(max_length=500)),
("mime_type", models.CharField(max_length=255)),
("size_bytes", models.BigIntegerField()),
("checksum_sha256", models.CharField(max_length=64)),
("is_public", models.BooleanField(default=False)),
("metadata", models.JSONField(default=dict)),
("created_at", models.DateTimeField(auto_now_add=True)),
(
"category",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="infrasynth_files.filecategory",
),
),
(
"tenant",
models.ForeignKey(
editable=False,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="tenancy.tenant",
),
),
(
"uploaded_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"db_table": "files_stored_file",
},
),
migrations.CreateModel(
name="PipelineExecution",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
(
"status",
models.CharField(
choices=[
("pending", "Pending"),
("running", "Running"),
("completed", "Completed"),
("failed", "Failed"),
],
default="pending",
max_length=20,
),
),
("started_at", models.DateTimeField(blank=True, null=True)),
("completed_at", models.DateTimeField(blank=True, null=True)),
("error", models.TextField(blank=True)),
(
"tenant",
models.ForeignKey(
editable=False,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="tenancy.tenant",
),
),
(
"pipeline",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="infrasynth_files.processingpipeline",
),
),
(
"file",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="pipeline_executions",
to="infrasynth_files.storedfile",
),
),
(
"output_file",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="infrasynth_files.storedfile",
),
),
],
options={
"db_table": "files_pipeline_execution",
},
),
migrations.AddConstraint(
model_name="filecategory",
constraint=models.UniqueConstraint(fields=("tenant", "slug"), name="uniq_file_category_slug_per_tenant"),
),
migrations.AddConstraint(
model_name="processingpipeline",
constraint=models.UniqueConstraint(fields=("tenant", "slug"), name="uniq_pipeline_slug_per_tenant"),
),
migrations.AddConstraint(
model_name="processingpipeline",
constraint=models.UniqueConstraint(
condition=models.Q(("tenant__isnull", True)), fields=("slug",), name="uniq_global_pipeline_slug"
),
),
migrations.AddIndex(
model_name="storedfile",
index=models.Index(fields=["tenant_id", "created_at"], name="files_store_tenant__340374_idx"),
),
migrations.AddIndex(
model_name="pipelineexecution",
index=models.Index(fields=["tenant_id", "status"], name="files_pipel_tenant__c309ab_idx"),
),
]