---
created: 2026-03-12
source: 50-Dollar-App
tags: [agent-archive, 50-dollar-app]
---

# ABN Uniqueness Constraint Migration Summary

## Migration File Created
- **File**: `supabase/migrations/20260208000001_add_abn_uniqueness_constraint.sql`
- **Purpose**: Adds UNIQUE constraint to the `abn` column in the `companies` table

## Key Steps

### 1. Pre-Migration Verification
Before running the migration, these queries help identify potential issues:
- Check for duplicate ABN values
- Count total companies with ABN values

### 2. Duplicate Handling Strategy
If duplicates exist:
- **Option A**: Nullify duplicate ABNs (preserves all companies)
- **Option B**: Manually review and update duplicates

### 3. Migration Actions
- Adds UNIQUE constraint to `companies.abn` column
- Ensures the performance index exists (`idx_companies_abn`)

### 4. Post-Migration Verification
- Verify no constraint violations exist
- Test inserting duplicate ABN (should fail)

## Important Notes
- The migration will FAIL if duplicate ABN values exist
- Always run verification queries before executing the migration
- The migration includes both UP and DOWN scripts for rollback capability

## Running the Migration
```bash
# Apply migration (from Supabase dashboard or CLI)
supabase db push 20260208000001_add_abn_uniqueness_constraint.sql

# Rollback if needed
supabase db reset --linked
```