feat(form-builder): per-schema default_crowd_type_id replaces silent oldest() heuristic (WS-6)
Session 2's PersonProvisioner picked CrowdType::oldest() for the org — silently wrong for multi-crowd_type orgs (Volunteer + Crew + Press are three distinct crowd_types in one org). Schemas now declare their target crowd_type explicitly via form_schemas.default_crowd_type_id. RequiresDefaultCrowdType publish guard prevents misconfigured event_registration schemas from publishing. PersonProvisioner: oldest() fallback removed entirely. Misconfiguration throws no_default_crowd_type at runtime; publish guard prevents it at config time. Migration uses a plain ulid() column without DB-level FK because SQLite's table-rebuild on ALTER ADD FOREIGN KEY cascade-deletes form_fields rows (form_fields.form_schema_id has cascadeOnDelete on form_schemas). Application-level integrity via FormSchema::defaultCrowdType() belongsTo + the publish guard + the runtime failsafe — three load-bearing checks, none of which require the DB-level constraint. Three pre-existing migration backfill tests bumped step counts +1 to account for the new migration sitting between WS-5c and WS-5d: FormFieldBindingMigrationTest (16→17, 14→15), FormFieldConfigBackfillAndDropTest (11→12), FormFieldValidationRuleBackfillTest (14→15), ConditionalLogicBackfillTest (5→6). Six event_registration test fixtures updated to set default_crowd_type_id to satisfy the new publish guard. FormBuilderDevSeeder.resolveDefaultCrowdTypeId() — VOLUNTEER → first-active → create-as-needed fallback chain; documented contract for future seeders. SCHEMA.md updated to v2.7. Refs: RFC-WS-6.md v1.1 §3 Q8 addendum (Task 4 of this session) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -80,7 +80,7 @@ final class FormBindingApplicatorIntegrationTest extends TestCase
|
||||
private function makeEventRegistrationSubmission(): FormSubmission
|
||||
{
|
||||
$event = Event::factory()->create();
|
||||
CrowdType::factory()->create([
|
||||
$crowdType = CrowdType::factory()->create([
|
||||
'organisation_id' => $event->organisation_id,
|
||||
'is_active' => true,
|
||||
]);
|
||||
@@ -88,6 +88,7 @@ final class FormBindingApplicatorIntegrationTest extends TestCase
|
||||
$schema = FormSchema::factory()->create([
|
||||
'organisation_id' => $event->organisation_id,
|
||||
'purpose' => FormPurpose::EVENT_REGISTRATION->value,
|
||||
'default_crowd_type_id' => $crowdType->id,
|
||||
]);
|
||||
|
||||
$emailField = FormField::factory()->create([
|
||||
|
||||
@@ -42,7 +42,7 @@ final class FormFieldBindingMigrationTest extends TestCase
|
||||
// validation-rules-backfill, create-validation-rules) +
|
||||
// 2 WS-6 migrations (action-failures, apply-status) +
|
||||
// 2 WS-5a migrations (drop-binding-cols, create-bindings) = 16.
|
||||
$this->artisan('migrate:rollback', ['--step' => 16])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 17])->assertSuccessful();
|
||||
$this->assertFalse(Schema::hasTable('form_field_bindings'));
|
||||
$this->assertTrue(Schema::hasColumn('form_fields', 'binding'));
|
||||
$this->assertTrue(Schema::hasColumn('form_field_library', 'default_binding'));
|
||||
@@ -104,7 +104,7 @@ final class FormFieldBindingMigrationTest extends TestCase
|
||||
public function test_rollback_reconstructs_json_and_drops_table(): void
|
||||
{
|
||||
// Walk back the full WS-5d + WS-5c + WS-6 + WS-5b + WS-5a stack (16 migrations).
|
||||
$this->artisan('migrate:rollback', ['--step' => 16])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 17])->assertSuccessful();
|
||||
[$fieldAId, , ] = $this->seedFieldsWithBindingJson();
|
||||
[$libAId, ] = $this->seedLibraryWithBindingJson();
|
||||
|
||||
@@ -119,7 +119,7 @@ final class FormFieldBindingMigrationTest extends TestCase
|
||||
// the pre-WS-5b state (conditional-logic, validation-rules, configs
|
||||
// and options tables gone, validation_rules + options JSON columns
|
||||
// reappear on source tables; binding contract intact).
|
||||
$this->artisan('migrate:rollback', ['--step' => 14])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 15])->assertSuccessful();
|
||||
$this->assertFalse(Schema::hasTable('form_field_options'));
|
||||
$this->assertFalse(Schema::hasTable('form_field_conditional_logic_groups'));
|
||||
$this->assertFalse(Schema::hasTable('form_field_conditional_logic_conditions'));
|
||||
|
||||
@@ -54,6 +54,13 @@ final class PublishChecksRelationalBindingsTest extends TestCase
|
||||
['name' => 'ER', 'purpose' => FormPurpose::EVENT_REGISTRATION->value],
|
||||
$this->actor,
|
||||
);
|
||||
// RFC v1.1 §3 Q8 addendum: event_registration schemas need a
|
||||
// default_crowd_type_id (RequiresDefaultCrowdType publish guard).
|
||||
$crowdType = \App\Models\CrowdType::factory()->create([
|
||||
'organisation_id' => $this->org->id,
|
||||
]);
|
||||
$schema->default_crowd_type_id = $crowdType->id;
|
||||
$schema->save();
|
||||
|
||||
// WS-6 publish guards require: EMAIL field type, identity_key flag
|
||||
// on person.email, unique trust levels per (entity, attribute).
|
||||
|
||||
Reference in New Issue
Block a user