# NGBVD UUID Migration Zero-Date Fix

## Problem

The UUID migration can fail on legacy MySQL/MariaDB databases where existing rows contain invalid date values such as:

```text
0000-00-00 00:00:00
```

When Laravel runs `ALTER TABLE ... ADD uuid ...`, MySQL may rebuild the table and revalidate existing datetime columns. In strict mode, this fails even though the migration is not directly modifying the datetime column.

## Fix

This patch updates:

```text
database/migrations/2026_06_04_000150_add_uuid_columns_to_reference_and_role_tables.php
```

It now:

1. Temporarily relaxes zero-date SQL mode for the migration session.
2. Normalises zero date/datetime/timestamp fields before altering each table.
3. Adds the `uuid` column only if it does not already exist.
4. Skips tables that are not present in the installed database.

## Commands

If the failed migration was partially applied, first inspect whether some UUID columns already exist. The replacement migration is idempotent and should skip existing UUID columns.

Then run:

```powershell
composer dump-autoload
php artisan optimize:clear
php artisan migrate --path=database/migrations/2026_06_04_000150_add_uuid_columns_to_reference_and_role_tables.php
```

Then continue the UUID backfill:

```powershell
php artisan ngbvd:backfill-uuids --chunk=2000
```

After backfill completes, run the index migration:

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