# Migration Cleanup Plan

## Current Status
- Highest numbered migration: **1005**
- Unnumbered migrations found: **11 files**

## Unnumbered Migrations Analysis

### 1. Datatable System (3 files - DUPLICATES)
- `create_datatable_system.sql` - Creates data_table_configurations
- `datatable_system_schema.sql` - Creates table_configurations (DUPLICATE)
- **Action**: Check if tables exist, keep one, archive the other

### 2. Datatable Configs (6 files - CONFIGURATION DATA)
- `clients_datatable_config.sql`
- `contacts_datatable_config.sql`
- `customers_datatable_config.sql`
- `documents_datatable_config.sql`
- `employees_datatable_config.sql`
- `quotes_datatable_config.sql`
- `positions_datatable_config.sql`
- **Action**: These insert config data, likely already applied. Archive them.

### 3. Client Hierarchy (1 file)
- `add_clients_hierarchy.sql` - Creates clients table
- **Action**: Check if clients table exists. If yes, archive. If no, number it.

### 4. Documentation (1 file)
- `RUN_MIGRATION_033.txt` - Instructions only
- **Action**: Delete (instructions, not a migration)

## Recommended Actions

### Step 1: Check What's Applied
Run these queries on your database:
```sql
-- Check for clients table
SHOW TABLES LIKE 'clients';

-- Check for datatable system
SHOW TABLES LIKE '%data_table%';
SHOW TABLES LIKE '%table_config%';
```

### Step 2: Archive Applied Migrations
```bash
mkdir -p database/migrations/archive
mv database/migrations/*_datatable_config.sql database/migrations/archive/
```

### Step 3: Future Numbering Scheme
Next migration should be: **1006_description.sql**

Format: `NNNN_descriptive_name.sql`
- 1006-1099: Reserved for features
- 1100+: Future expansion

### Step 4: Clean Up
- Delete `RUN_MIGRATION_033.txt`
- Move duplicate datatable schemas to archive

## Next Migration Number: 1006
