# Database Migrations

This directory contains SQL migration files for the database schema.

## Migration Files

1. **001_initial_schema.sql** - Initial database schema
   - Users, documents, deals, verifiable credentials, signatures, ledger entries, payments

2. **002_add_indexes.sql** - Performance indexes
   - Indexes on frequently queried columns

3. **003_credential_lifecycle.sql** - Credential lifecycle management
   - Credential templates
   - Credential status history
   - Credential revocation registry
   - Credential issuance audit log
   - Expiration tracking indexes

## Running Migrations

Migrations should be run in order using your database migration tool (e.g., `node-pg-migrate`, `knex`, or manual execution).

### Manual Execution

```bash
# Connect to your database
psql $DATABASE_URL

# Run migrations in order
\i packages/database/src/migrations/001_initial_schema.sql
\i packages/database/src/migrations/002_add_indexes.sql
\i packages/database/src/migrations/003_credential_lifecycle.sql
```

### Using Migration Tool

If using a migration tool, ensure migrations are run in the correct order (001, 002, 003).

## Migration Status

- ✅ 001_initial_schema.sql - Initial schema
- ✅ 002_add_indexes.sql - Performance indexes
- ✅ 003_credential_lifecycle.sql - Credential lifecycle

## Notes

- All migrations use `IF NOT EXISTS` clauses where appropriate to allow idempotent execution
- Migrations should be tested in a development environment before production deployment
- Always backup your database before running migrations in production

