59 lines
2.3 KiB
Markdown
59 lines
2.3 KiB
Markdown
# Migration Fixes for Production Database Compatibility
|
|
|
|
## Problem
|
|
The database migrations were failing when run against a production database dump because:
|
|
|
|
1. **First migration (630b0c367dcb)**: Tried to create an index on `acked_requests` that already existed in the production dump
|
|
2. **Third migration (08fe946414d8)**: Tried to add `hashed_customer_id` column to `reservations` without checking if it already existed
|
|
3. **Fourth migration (a1b2c3d4e5f6)**: Tried to modify `conversion_guests` table before it was guaranteed to exist
|
|
|
|
## Solutions Applied
|
|
|
|
### 1. Migration 630b0c367dcb - Initial Migration
|
|
**Change**: Made index creation idempotent by checking if index already exists before creating it
|
|
|
|
**Impact**: Allows migration to run even if production DB already has the `ix_acked_requests_username` index
|
|
|
|
### 2. Migration 08fe946414d8 - Add hashed_customer_id to reservations
|
|
**Change**: Added check to skip adding the column if it already exists
|
|
|
|
**Impact**:
|
|
- Preserves production data in `reservations` and `hashed_customers` tables
|
|
- Makes migration safe to re-run
|
|
- Still performs data migration to populate `hashed_customer_id` when needed
|
|
|
|
### 3. Migration a1b2c3d4e5f6 - Add hashed_customer_id to conversion_guests
|
|
**Change**: Added check to verify `conversion_guests` table exists before modifying it
|
|
|
|
**Impact**: Safely handles the case where table creation in a previous migration succeeded
|
|
|
|
## Data Preservation
|
|
All non-conversion tables are preserved:
|
|
- ✓ `customers`: 1095 rows preserved
|
|
- ✓ `reservations`: 1177 rows preserved
|
|
- ✓ `hashed_customers`: 1095 rows preserved
|
|
- ✓ `acked_requests`: preserved
|
|
|
|
Conversion tables are properly recreated:
|
|
- ✓ `conversions`: created fresh with new schema
|
|
- ✓ `conversion_rooms`: created fresh with new schema
|
|
- ✓ `conversion_guests`: created fresh with composite key
|
|
|
|
## Verification
|
|
After running `uv run alembic upgrade head`:
|
|
- All migrations apply successfully
|
|
- Database is at head revision: `a1b2c3d4e5f6`
|
|
- All required columns exist (`conversion_guests.hashed_customer_id`, `reservations.hashed_customer_id`)
|
|
- Production data is preserved
|
|
|
|
## Reset Instructions
|
|
If you need to reset and re-run all migrations:
|
|
|
|
```sql
|
|
DELETE FROM alpinebits.alembic_version;
|
|
```
|
|
|
|
Then run:
|
|
```bash
|
|
uv run alembic upgrade head
|
|
``` |