# Next Steps for MySQL Migration

## Current Status

✅ **Completed:**
- MSSQL to MySQL schema conversion
- AUTO_INCREMENT PRIMARY KEY fixes (89 tables)
- Duplicate ALTER TABLE removal (85 statements)
- Data file conversion scripts ready

⚠️ **Current Issue:**
- Schema import failing due to duplicate column removal being too aggressive
- Need to refine duplicate column detection

## Recommended Next Steps (Priority Order)

### 1. **Fix Schema Import** (HIGH PRIORITY)
**Problem:** The duplicate column fix removed legitimate columns, breaking the schema.

**Solution Options:**
- **Option A (Recommended):** Re-run conversion without duplicate column fix, then manually fix only the actual problematic duplicates
- **Option B:** Refine `fix_duplicate_columns.py` to only remove true duplicates (same case-insensitive name in same table)

**Action:**
```bash
cd database_dump
# Re-convert fresh
python3 convert_mssql_to_mysql.py
python3 fix_all_tables_primary_key.py
# Test import
mysql -u root -p LRS43 < mysql/schema_mysql_20251113_185155.sql
```

### 2. **Complete Full Schema Import** (HIGH PRIORITY)
Once schema imports successfully:
- Verify all 168 tables are created
- Check for any remaining errors
- Validate table structures

**Command:**
```bash
mysql -u root -p LRS43 -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'LRS43';"
```

### 3. **Import Sample Data** (MEDIUM PRIORITY)
Test data import with the converted data files:
- `data_mysql_alf_*.sql`
- `data_mysql_lr_*.sql`

**Action:**
```bash
cd database_dump/mysql
for file in data_mysql_*.sql; do
    echo "Importing $file..."
    mysql -u root -p LRS43 < "$file"
done
```

### 4. **Fix Remaining Schema Issues** (MEDIUM PRIORITY)
If any tables fail to import:
- Identify specific error messages
- Fix on a case-by-case basis
- May need to handle:
  - Foreign key constraints
  - Index definitions
  - Data type mismatches

### 5. **Update Application Code** (LOW PRIORITY - Already Started)
Verify database connections are updated:
- ✅ `aumentum_browser_service.py` - Already supports MySQL
- Check other connection points from `DATABASE_CONNECTIONS.md`
- Test application connectivity

### 6. **Performance Testing** (LOW PRIORITY)
Once everything imports:
- Test query performance
- Verify indexes are created correctly
- Check for any missing constraints

## Quick Fix Command

To get back to a working state:

```bash
cd /home/stark/Downloads/PLAGIS_AUMENTUM-main/database_dump

# 1. Re-convert from original MSSQL schema (fresh start)
python3 convert_mssql_to_mysql.py

# 2. Fix PRIMARY KEY issues
python3 fix_all_tables_primary_key.py

# 3. Test import (don't run duplicate column fix yet)
cd mysql
mysql -u root -p'Derickche47*' LRS43 -e "DROP DATABASE IF EXISTS LRS43; CREATE DATABASE LRS43 CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql -u root -p'Derickche47*' LRS43 < schema_mysql_20251113_185155.sql 2>&1 | head -20
```

## Files to Review

1. **`fix_duplicate_columns.py`** - Needs refinement to be less aggressive
2. **`schema_mysql_20251113_185155.sql`** - Current schema file
3. **`convert_mssql_to_mysql.py`** - Main conversion script (working)
4. **`fix_all_tables_primary_key.py`** - PRIMARY KEY fixer (working)

## Expected Outcome

After completing these steps:
- ✅ Full schema imported (168 tables)
- ✅ All AUTO_INCREMENT columns have PRIMARY KEY
- ✅ Sample data imported successfully
- ✅ Application can connect to MySQL database
- ✅ Ready for production migration

