-- =====================================================
-- RUN ALL PHASE 4 SCRIPTS: Application Versions
-- =====================================================
-- Date: 2025-11-25
-- Purpose: Execute all Phase 4 migration scripts in order
--
-- USAGE:
--   mysql -u root -p shopdb < RUN_ALL_PHASE4_SCRIPTS.sql
--
-- OR run each script individually:
--   1. 01_create_appversions_table.sql
--   2. 02_add_appversionid_to_installedapps.sql
--   3. 03_add_appid_to_notifications.sql
--   4. VERIFY_PHASE4_MIGRATION.sql
--
-- ROLLBACK ORDER (if needed):
--   1. ROLLBACK_03_notifications_appid.sql
--   2. ROLLBACK_02_installedapps_appversionid.sql
--   3. ROLLBACK_01_appversions_table.sql
-- =====================================================

USE shopdb;

SELECT '=================================================' AS '';
SELECT 'PHASE 4 MIGRATION: Application Versions' AS '';
SELECT 'Started at: ' AS '', NOW() AS timestamp;
SELECT '=================================================' AS '';

-- =====================================================
-- PRE-MIGRATION BACKUP REMINDER
-- =====================================================
SELECT 'REMINDER: Ensure you have a database backup before proceeding!' AS '';
SELECT '' AS '';

-- =====================================================
-- SCRIPT 1: Create appversions table
-- =====================================================
SELECT '--- Running Script 01: Create appversions table ---' AS '';

SOURCE 01_create_appversions_table.sql;

-- =====================================================
-- SCRIPT 2: Add appversionid to installedapps
-- =====================================================
SELECT '--- Running Script 02: Add appversionid to installedapps ---' AS '';

SOURCE 02_add_appversionid_to_installedapps.sql;

-- =====================================================
-- SCRIPT 3: Add appid to notifications
-- =====================================================
SELECT '--- Running Script 03: Add appid to notifications ---' AS '';

SOURCE 03_add_appid_to_notifications.sql;

-- =====================================================
-- VERIFICATION
-- =====================================================
SELECT '--- Running Verification ---' AS '';

SOURCE VERIFY_PHASE4_MIGRATION.sql;

-- =====================================================
-- COMPLETE
-- =====================================================
SELECT '=================================================' AS '';
SELECT 'PHASE 4 MIGRATION COMPLETE' AS '';
SELECT 'Finished at: ' AS '', NOW() AS timestamp;
SELECT '=================================================' AS '';
SELECT '' AS '';
SELECT 'NEXT STEPS:' AS '';
SELECT '1. Update api.asp to use appversions table' AS '';
SELECT '2. Update PowerShell script to send version data' AS '';
SELECT '3. Update notification forms to allow app selection' AS '';
SELECT '=================================================' AS '';
