refactor(form-builder): drop custom purpose escape from schemas

Reduces the FormPurpose vocabulary from 22 variants + a `custom` escape
to the seven v1.0 purposes registered in the new PurposeRegistry.

- Purge migration deletes any form_schemas row whose `purpose` is not
  in the v1.0 set (cascades through form_fields, form_submissions,
  form_values, form_value_options, form_schema_sections,
  form_submission_section_statuses, form_submission_delegations,
  form_schema_webhooks, form_webhook_deliveries via existing FK).
- Drop migration removes the `custom_purpose_slug` column + its index.
- Both migrations declare their `down()` as a hard failure — we do not
  support reversing a purge (pre-launch, no production data).
- `FormPurpose` enum slims to the seven cases; the legacy helpers
  (defaultSubmissionMode / defaultSubjectType / allowsPublicAccess)
  now delegate to PurposeRegistry so callers keep working.
- FormSchema fillable / FormSchemaResource / StoreFormSchemaRequest /
  UpdateFormSchemaRequest / FormSchemaFactory drop every reference to
  `custom_purpose_slug` and the `custom` purpose.
- VerifyFormsDataIntegrity drops the custom-slug mismatch check and
  sources the subject-type allow-list from PurposeRegistry.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 14:35:37 +02:00
parent e93207765b
commit b9343f6eec
9 changed files with 162 additions and 120 deletions

View File

@@ -6,6 +6,7 @@ namespace App\Console\Commands;
use App\Enums\FormBuilder\FormFieldType;
use App\Enums\FormBuilder\FormPurpose;
use App\FormBuilder\Purposes\PurposeRegistry;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
@@ -68,18 +69,6 @@ final class VerifyFormsDataIntegrity extends Command
->whereNotIn('purpose', $purposeValues)
->count();
$customMismatch = DB::table('form_schemas')
->where(function ($q): void {
$q->where(function ($q): void {
$q->where('purpose', FormPurpose::CUSTOM->value)
->whereNull('custom_purpose_slug');
})->orWhere(function ($q): void {
$q->where('purpose', '!=', FormPurpose::CUSTOM->value)
->whereNotNull('custom_purpose_slug');
});
})
->count();
$publicTokenDupes = DB::table('form_schemas')
->whereNotNull('public_token')
->select('public_token')
@@ -87,9 +76,9 @@ final class VerifyFormsDataIntegrity extends Command
->havingRaw('COUNT(*) > 1')
->count();
if ($invalidPurpose > 0 || $customMismatch > 0 || $publicTokenDupes > 0) {
if ($invalidPurpose > 0 || $publicTokenDupes > 0) {
$this->recordFailure('Schema coherence',
"{$invalidPurpose} invalid purpose, {$customMismatch} custom_purpose_slug mismatches, {$publicTokenDupes} duplicate public_tokens"
"{$invalidPurpose} invalid purpose, {$publicTokenDupes} duplicate public_tokens"
);
return;
@@ -190,7 +179,7 @@ final class VerifyFormsDataIntegrity extends Command
})
->count();
$subjectTypes = array_keys((array) config('form_subjects', []));
$subjectTypes = app(PurposeRegistry::class)->allSubjectTypes();
$invalidSubjectType = DB::table('form_submissions')
->whereNotNull('subject_type')
->whereNotIn('subject_type', $subjectTypes)