whisper-money/database/migrations
Víctor Falcón 683b3f32a7
feat: Send custom emails to users (#52)
## Overview

This PR adds a flexible system for sending update emails to all Whisper
Money users. As the solo developer, you can now easily communicate
product updates, announcements, and news to your growing user base.

## Problem Solved

- **No easy way to send announcements**: Previously, there was no simple
way to broadcast important updates to all users
- **Manual process**: Would require writing custom scripts each time
- **No duplicate prevention**: Risk of accidentally sending the same
email multiple times
- **Version control**: Email content wasn't tracked in git

## Solution

A complete email system that lets you:
1. Write update emails as markdown templates (version controlled)
2. Send them with a single command
3. Automatic duplicate prevention (users only receive each update once)
4. Track who received what in the database

## How It Works

### 1. Create Email Template

Create a markdown file in `resources/views/mail/updates/`:

```blade
<x-mail::message>
# What's New in January 2026

Hi {{ $user->name }},

Your update content here...

<x-mail::button :url="'https://discord.gg/9UQWZECDDv'">
Join the Discord Community
</x-mail::button>

Víctor Falcón Ruíz
Founder & Solo Developer, Whisper Money
</x-mail::message>
```

### 2. Send to All Users

```bash
# Simple - one command
php artisan email:update first-update-jan-2026

# With options
php artisan email:update first-update-jan-2026 --subject="Personal Thank You" --exclude-demo
```

### 3. Automatic Tracking

- Users only receive each update once (tracked by identifier)
- Can send different updates to same users
- View history in `user_mail_logs` table

## First Email Included

The PR includes the first update email (`first-update-jan-2026`)
announcing:
- 240+ GitHub stars milestone
- First paying users
- Discord community invitation
- Canny roadmap links
- Personal message from Víctor as the solo developer

## Technical Details

### What's New

**Database:**
- Migration: Add `email_identifier` column to `user_mail_logs`
- Migration: Update unique constraint to `(user_id, email_type,
email_identifier)`

**Backend:**
- `DripEmailType` enum: Added `Update` case
- `UpdateEmail` mailable: Generic mailable accepting any view
- `SendUpdateEmailJob`: Handles sending + duplicate prevention
- `SendUpdateEmailCommand`: Artisan command with progress bar
- Updated all 6 drip email jobs to support new constraint

**Frontend:**
- Email template directory: `resources/views/mail/updates/`
- Comprehensive README with examples

**Tests:**
- Complete test suite: 11 tests covering all scenarios
- Tests duplicate prevention, filtering, queue behavior

### Command Options

```bash
php artisan email:update <view> [identifier] [options]

Arguments:
  view          Template name (e.g., "jan-2026-updates")
  identifier    Tracking ID (defaults to view name)

Options:
  --subject=    Custom email subject
  --exclude-demo   Skip demo account
  --force       Skip confirmation prompt
```

## Benefits

1. **Simple**: One command to send any update email
2. **Flexible**: Just create a new markdown view, no code changes needed
3. **Safe**: Confirmation prompt and duplicate prevention
4. **Fast**: Queued delivery, non-blocking
5. **Tracked**: Full audit trail in UserMailLog
6. **Consistent**: Follows existing drip email patterns
7. **Reusable**: Same command for all future update emails
8. **Version Controlled**: Email content is in git, reviewable

## Migration Path

To use in production:

```bash
# 1. Run migrations
php artisan migrate

# 2. Create your email template
vim resources/views/mail/updates/your-update.blade.php

# 3. Commit and deploy
git add resources/views/mail/updates/your-update.blade.php
git commit -m "Add update email"
git push

# 4. Send on production
php artisan email:update your-update
```

## Example Use Cases

- Product announcements
- New feature launches  
- Community updates
- Milestone celebrations
- Important notifications
- Partnership announcements

## Files Changed

### Created
- `database/migrations/*_add_email_identifier_to_user_mail_logs.php`
- `database/migrations/*_update_user_mail_logs_unique_constraint.php`
- `app/Mail/UpdateEmail.php`
- `app/Jobs/SendUpdateEmailJob.php`
- `app/Console/Commands/SendUpdateEmailCommand.php`
- `resources/views/mail/updates/first-update-jan-2026.blade.php`
- `resources/views/mail/updates/README.md`
- `tests/Feature/Console/SendUpdateEmailCommandTest.php`

### Modified
- `app/Enums/DripEmailType.php` (added Update case)
- `app/Models/UserMailLog.php` (added email_identifier field)
- All 6 drip email jobs (added email_identifier support)

## Testing

All tests passing (11 tests, 27 assertions):
-  Command dispatches jobs for all users
-  Command excludes demo account when flag is set
-  Command fails when view does not exist
-  Command uses custom subject when provided
-  Job is dispatched to emails queue
-  Command handles empty user database gracefully
-  Job skips users who already received the update
-  Job creates mail log entry after sending
-  Job sends email with correct view and user data
-  Command requires confirmation by default
-  Command skips confirmation with force flag
2026-01-09 09:33:19 +01:00
..
0001_01_01_000000_create_users_table.php Set up a fresh Laravel app 2025-11-07 12:01:36 +00:00
0001_01_01_000001_create_cache_table.php Set up a fresh Laravel app 2025-11-07 12:01:36 +00:00
0001_01_01_000002_create_jobs_table.php Set up a fresh Laravel app 2025-11-07 12:01:36 +00:00
2025_08_26_100418_add_two_factor_columns_to_users_table.php Set up a fresh Laravel app 2025-11-07 12:01:36 +00:00
2025_11_07_135255_add_encryption_salt_to_users_table.php E2E Encryption 2025-11-07 14:21:25 +00:00
2025_11_07_135256_create_encrypted_messages_table.php E2E Encryption 2025-11-07 14:21:25 +00:00
2025_11_07_150038_create_banks_table.php feat: Add financial models and seeders 2025-11-07 15:45:28 +00:00
2025_11_07_150122_create_accounts_table.php feat: Add financial models and seeders 2025-11-07 15:45:28 +00:00
2025_11_07_150613_create_categories_table.php feat: Add financial models and seeders 2025-11-07 15:45:28 +00:00
2025_11_07_150659_create_transactions_table.php feat: Add financial models and seeders 2025-11-07 15:45:28 +00:00
2025_11_07_184056_modify_banks_table_add_user_id_and_simplify_name.php Banks accounts 2025-11-07 19:19:29 +00:00
2025_11_07_185018_change_banks_logo_to_text.php Banks accounts 2025-11-07 19:19:29 +00:00
2025_11_08_140230_change_transactions_id_to_uuid.php Update transaction amount to bigint 2025-11-15 20:53:47 +01:00
2025_11_08_141344_make_category_id_nullable_in_transactions_table.php Sync transactions 2025-11-08 14:17:16 +00:00
2025_11_08_144530_add_soft_deletes_to_transactions_table.php Transactions page 2025-11-08 23:38:35 +00:00
2025_11_10_110100_create_automation_rules_table.php Automation rules 2025-11-10 12:08:58 +00:00
2025_11_15_172640_create_account_balances_table.php Add account balances 2025-11-15 20:27:18 +01:00
2025_11_15_175636_change_transactions_amount_to_bigint.php Update transaction amount to bigint 2025-11-15 20:53:47 +01:00
2025_11_15_195739_convert_all_ids_to_uuid.php fix: migration history 2025-12-30 07:22:19 +01:00
2025_11_18_184409_create_user_leads_table.php Merge pull request #1 from whisper-money/landing-page 2025-11-24 12:11:35 +01:00
2025_11_28_104227_add_source_to_transactions_table.php Save transaction source (manually_created, or imported) 2025-11-28 12:36:48 +01:00
2025_11_29_170353_add_type_to_categories_table.php Add category type field support (#2) 2025-12-01 20:19:47 +01:00
2025_11_29_170955_fix_account_balances_unique_constraint.php fix: migration history 2025-12-30 07:22:19 +01:00
2025_12_01_101443_add_unique_constraint_to_categories_table.php Add unique constraint to categories table and update factory data 2025-12-01 11:19:16 +01:00
2025_12_06_112515_create_customer_columns.php Subscriptions (#15) 2025-12-06 19:09:56 +01:00
2025_12_06_112516_create_subscriptions_table.php Subscriptions (#15) 2025-12-06 19:09:56 +01:00
2025_12_06_112517_create_subscription_items_table.php Subscriptions (#15) 2025-12-06 19:09:56 +01:00
2025_12_06_112518_add_meter_id_to_subscription_items_table.php Subscriptions (#15) 2025-12-06 19:09:56 +01:00
2025_12_06_112519_add_meter_event_name_to_subscription_items_table.php Subscriptions (#15) 2025-12-06 19:09:56 +01:00
2025_12_10_142006_add_onboarded_at_to_users_table.php User Onboarding Flow (#23) 2025-12-12 13:06:08 +01:00
2025_12_12_092647_create_labels_table.php feat: add transaction labels feature (#24) 2025-12-13 13:02:19 +01:00
2025_12_12_092650_create_label_transaction_table.php feat: add transaction labels feature (#24) 2025-12-13 13:02:19 +01:00
2025_12_12_092651_create_automation_rule_labels_table.php feat: add transaction labels feature (#24) 2025-12-13 13:02:19 +01:00
2025_12_12_141955_update_labels_unique_constraint_include_deleted_at.php feat: add transaction labels feature (#24) 2025-12-13 13:02:19 +01:00
2025_12_16_151952_create_user_mail_logs_table.php feat: Implement drip email campaign system (#35) 2025-12-30 07:22:18 +01:00
2025_12_20_154221_create_features_table.php Add Cashflow Analytics Feature (#49) 2026-01-05 13:06:50 +01:00
2025_12_29_063338_add_currency_code_to_users_table.php Add currency selection to user profile settings (#41) 2025-12-30 07:22:19 +01:00
2026_01_08_192757_add_email_identifier_to_user_mail_logs.php feat: Send custom emails to users (#52) 2026-01-09 09:33:19 +01:00
2026_01_08_204223_update_user_mail_logs_unique_constraint.php feat: Send custom emails to users (#52) 2026-01-09 09:33:19 +01:00