# NGBVD Role Form and UUID Reference Implementation

## Role form correction

The `/roles/index` form was posting to `/dataentry/postfmg` because the view had inherited the FGM form scaffold and hard-coded:

```php
$posturl = url("dataentry/postfmg");
```

This has been corrected. The role form now posts to:

```text
POST /roles/save
```

The edit view now loads an existing role using either UUID or legacy ID:

```text
GET /roles/index?id={role_uuid}
```

## UUID implementation standard

The system now starts referencing roles and reference data by UUID where available. This patch does not drop legacy integer IDs because existing foreign keys and historical data still depend on them.

Safe approach implemented:

1. Add `uuid` columns to role and reference tables.
2. Backfill UUIDs in chunks using the Artisan command.
3. Use UUIDs in URLs and external references.
4. Add unique UUID indexes only after backfill.
5. Convert foreign keys to UUIDs in a later controlled migration after relationship mapping.

## Commands

Run migrations:

```powershell
php artisan migrate --path=database/migrations/2026_06_04_000150_add_uuid_columns_to_reference_and_role_tables.php
```

Backfill UUIDs:

```powershell
php artisan ngbvd:backfill-uuids --table=user_roles --chunk=1000
php artisan ngbvd:backfill-uuids --table=role_permissions --chunk=1000
php artisan ngbvd:backfill-uuids --chunk=2000
```

After all UUID columns are populated:

```powershell
php artisan migrate --path=database/migrations/2026_06_04_000160_add_uuid_indexes_to_reference_and_role_tables.php
```

## Testing

1. Open `/roles/index` and create a new role.
2. Confirm it redirects to `/roles/list`.
3. Click Edit on a role.
4. Confirm the role name loads.
5. Update the name and save.
6. Click Configure and confirm permissions still save.
7. Confirm role URLs use UUID when the UUID has been backfilled.
