-- ========================================
-- SIMPLE DEPLOYMENT - No Staging Tables Needed
-- Positions & Roles to Production
-- ========================================
-- Uses REPLACE INTO which automatically handles:
-- - UPDATE if record exists
-- - INSERT if record doesn't exist
-- No staging tables = No locking issues
-- ========================================

USE m1_erp;

-- Show before state
SELECT '=== BEFORE DEPLOYMENT ===' as Status;
SELECT 'Current Positions:' as Info, COUNT(*) as Count FROM positions;
SELECT 'Current Roles:' as Info, COUNT(*) as Count FROM roles;

-- Create backups
CREATE TABLE positions_backup_20260210 AS SELECT * FROM positions;

CREATE TABLE roles_backup_20260210 AS SELECT * FROM roles;

SELECT '=== BACKUPS CREATED ===' as Status;
SELECT CONCAT('Backed up ', COUNT(*), ' positions') as Info FROM positions_backup_20260210;
SELECT CONCAT('Backed up ', COUNT(*), ' roles') as Info FROM roles_backup_20260210;

-- ========================================
-- NOW IMPORT THE DATA FILES
-- ========================================
-- In phpMyAdmin:
-- 1. Run this script first (creates backups)
-- 2. Then create modified data files with REPLACE INTO
-- ========================================

-- After running data files, verify:
SELECT '=== AFTER DEPLOYMENT ===' as Status;
SELECT 'Final Positions:' as Info, COUNT(*) as Count FROM positions;
SELECT 'Final Roles:' as Info, COUNT(*) as Count FROM roles;
SELECT 'Active Positions:' as Info, COUNT(*) as Count FROM positions WHERE is_active = 1;
