# `PhoenixKit.Migrations.Postgres.V19`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.87/lib/phoenix_kit/migrations/postgres/v19.ex#L1)

PhoenixKit V19 Migration: Enhanced Email Status Tracking

Adds additional timestamp fields to phoenix_kit_email_logs table for comprehensive
email lifecycle tracking, enabling full visibility from queue to delivery.

## Changes

### Email Logs Table (phoenix_kit_email_logs)
- Adds `queued_at` timestamp for when email enters send queue
- Adds `rejected_at` timestamp for provider rejections
- Adds `failed_at` timestamp for send failures
- Adds `delayed_at` timestamp for delivery delays

## Features

- **Complete Lifecycle Tracking**: Track emails from queued → sent → delivered
- **Failure Timestamps**: Precise timing for rejections and failures
- **Delay Tracking**: Monitor when emails experience delivery delays
- **Status History**: Enhanced audit trail with granular timestamps

## Email Status Flow

```
QUEUED (queued_at) → SENT (sent_at) → DELIVERED (delivered_at)
                  ↘ FAILED (failed_at)
                  ↘ REJECTED (rejected_at)

DELIVERED → OPENED (opened_at) → CLICKED (clicked_at)
         ↘ HARD_BOUNCED/SOFT_BOUNCED (bounced_at)
         ↘ COMPLAINT (complained_at)
         ↘ DELAYED (delayed_at)
```

## Usage Examples

```elixir
# Email queued for sending
Log.create_log(%{..., status: "queued", queued_at: DateTime.utc_now()})

# Email sent to provider
Log.update_status(log, "sent", %{sent_at: DateTime.utc_now()})

# Email delivery confirmed
Log.mark_as_delivered(log, DateTime.utc_now())

# Email rejected by provider
Log.mark_as_rejected(log, "Invalid recipient", DateTime.utc_now())
```

# `down`

Rollback the V19 migration.

# `up`

Run the V19 migration to add enhanced email status tracking fields.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
