feat(form-builder): retry history table + integration (WS-6)

Per-attempt retry history (timestamp, user, outcome, exception detail
if failed) replaces the counter-only retry_count tracking.

Changes:

- New `form_submission_action_failure_retry_attempts` table (cascade on
  parent delete, nullOnDelete on user). Explicit short FK names
  (`fsafra_failure_fk`, `fsafra_user_fk`) — auto-generated names exceed
  MySQL's 64-char identifier limit.
- New FormSubmissionActionFailureRetryAttempt model + factory +
  succeeded() state.
- Parent FormSubmissionActionFailure gets retryAttempts() HasMany
  relation (latest('attempted_at')).
- New FormFailureRetryService centralises the retry-flow logic. Both
  the API controller and the artisan command delegate to it. Service
  writes a retry_attempt record per attempt; parent's retry_count
  stays as denormalised cache for index-view performance.
- Successful retry: attempt(succeeded) + parent.retry_count++ +
  parent.resolved_at + parent.resolved_by_user_id + parent.resolved_note
  ("Geslaagde retry door {actor.name}" or "Geslaagde retry
  (geautomatiseerd)" for command-line invocation without an actor).
- Failed retry: attempt(failed) with NEW exception details +
  parent.retry_count++. Parent's exception_class/_message stay
  audit-immutable — they represent the FIRST failure.
- canBeRetried() now correctly checks both resolved_at AND
  dismissed_at (sessie 2's open question Q2 closure).
- New FailureNotRetriableException (controller → 422) and
  ParentSubmissionGoneException (controller → 410) for cleaner
  flow control.

12 new tests:
- FormSubmissionActionFailureRetryAttemptTest (5 unit tests)
- RetryFlowProducesRetryAttemptsTest (7 integration tests covering
  succeeded path, failed path, resolved/dismissed blocking,
  multiple-retries chronological ordering, canBeRetried truth tables)

Pre-existing tests touched:
- FormSubmissionActionFailureTest::test_can_be_retried_only_for_open_state
  — updated to reflect Q2 closure (resolved now blocks too).
- Ws6FoundationMigrationTest::test_down_methods_clean_up_columns_and_table
  — child table must drop before parent (FK constraint).
- 5 backfill test step-counts bumped +1 (new migration sits at top).

SCHEMA.md → v2.9. Schema dump regenerated.

Refs: RFC-WS-6.md §3 Q5 addendum, sessie 2 Q2

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-28 22:53:36 +02:00
parent acd7cf5ec8
commit b47e096a55
20 changed files with 767 additions and 123 deletions

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Database\Factories\FormBuilder;
use App\Exceptions\FormBuilder\PersonProvisioningException;
use App\Models\FormBuilder\FormSubmissionActionFailure;
use App\Models\FormBuilder\FormSubmissionActionFailureRetryAttempt;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/** @extends Factory<FormSubmissionActionFailureRetryAttempt> */
final class FormSubmissionActionFailureRetryAttemptFactory extends Factory
{
protected $model = FormSubmissionActionFailureRetryAttempt::class;
/** @return array<model-property<FormSubmissionActionFailureRetryAttempt>, mixed> */
public function definition(): array
{
return [
'form_submission_action_failure_id' => FormSubmissionActionFailure::factory(),
'attempted_at' => fake()->dateTimeBetween('-7 days', 'now'),
'attempted_by_user_id' => User::factory(),
'outcome' => 'failed',
'exception_class' => PersonProvisioningException::class,
'exception_message' => 'Person provisioning failed: no_default_crowd_type',
];
}
public function succeeded(): static
{
return $this->state(fn (): array => [
'outcome' => 'succeeded',
'exception_class' => null,
'exception_message' => null,
]);
}
}

View File

@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* RFC-WS-6.md §3 (Q5) addendum per-attempt retry history.
*
* Sessie 1's form_submission_action_failures.retry_count is a counter
* only. Sessie 3c adds per-attempt records (timestamp, user, outcome,
* exception details if failed) so the admin UI can show retry history.
*
* retry_count on the parent stays as denormalized cache for index-view
* performance. Service layer keeps both in sync per retry.
*
* No backfill: pre-launch the table is empty and dev seeders re-seed
* every iteration.
*
* Note on constraint names: the table name is 43 chars long; auto-generated
* FK constraint names (`{table}_{column}_foreign`) exceed MySQL's 64-char
* identifier limit. Each FK uses an explicit short name below.
*/
return new class extends Migration
{
public function up(): void
{
Schema::create('form_submission_action_failure_retry_attempts', function (Blueprint $table): void {
$table->ulid('id')->primary();
$table->ulid('form_submission_action_failure_id');
$table->timestamp('attempted_at');
$table->ulid('attempted_by_user_id')->nullable();
$table->enum('outcome', ['succeeded', 'failed']);
$table->string('exception_class', 255)->nullable();
$table->text('exception_message')->nullable();
$table->timestamps();
$table->foreign('form_submission_action_failure_id', 'fsafra_failure_fk')
->references('id')
->on('form_submission_action_failures')
->cascadeOnDelete();
$table->foreign('attempted_by_user_id', 'fsafra_user_fk')
->references('id')
->on('users')
->nullOnDelete();
$table->index(['form_submission_action_failure_id', 'attempted_at'], 'fsafra_failure_attempt_idx');
});
}
public function down(): void
{
Schema::dropIfExists('form_submission_action_failure_retry_attempts');
}
};

View File

@@ -111,7 +111,7 @@ CREATE TABLE `companies` (
`organisation_id` char(26) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`type` enum('supplier','partner','agency','venue','other') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`kvk_number` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`kvk_number` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`contact_first_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`contact_last_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`contact_email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
@@ -624,6 +624,26 @@ CREATE TABLE `form_schemas` (
CONSTRAINT `form_schemas_organisation_id_foreign` FOREIGN KEY (`organisation_id`) REFERENCES `organisations` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `form_submission_action_failure_retry_attempts`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `form_submission_action_failure_retry_attempts` (
`id` char(26) COLLATE utf8mb4_unicode_ci NOT NULL,
`form_submission_action_failure_id` char(26) COLLATE utf8mb4_unicode_ci NOT NULL,
`attempted_at` timestamp NOT NULL,
`attempted_by_user_id` char(26) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`outcome` enum('succeeded','failed') COLLATE utf8mb4_unicode_ci NOT NULL,
`exception_class` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`exception_message` text COLLATE utf8mb4_unicode_ci,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fsafra_user_fk` (`attempted_by_user_id`),
KEY `fsafra_failure_attempt_idx` (`form_submission_action_failure_id`,`attempted_at`),
CONSTRAINT `fsafra_failure_fk` FOREIGN KEY (`form_submission_action_failure_id`) REFERENCES `form_submission_action_failures` (`id`) ON DELETE CASCADE,
CONSTRAINT `fsafra_user_fk` FOREIGN KEY (`attempted_by_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `form_submission_action_failures`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
@@ -1750,3 +1770,4 @@ INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (153,'2026_04_27_10
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (154,'2026_04_27_100002_drop_form_field_options_json_columns',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (155,'2026_04_28_100000_restore_default_crowd_type_id_foreign_key',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (156,'2026_04_28_140000_add_kvk_number_to_companies_table',3);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (157,'2026_04_28_180000_create_form_submission_action_failure_retry_attempts_table',4);