-- ============================================================
-- FIX EXPENSES TABLE ID COLUMN
-- ============================================================
-- IMPORTANT: Make sure you select database 'acbptxvs_branch_system' 
-- in phpMyAdmin before running this script!
-- ============================================================

-- Step 1: Check current structure
DESCRIBE expenses;

-- Step 2: Check how many records exist
SELECT COUNT(*) as total_expenses FROM expenses;

-- Step 3: Create backup (IMPORTANT!)
-- Run these one at a time:
DROP TABLE IF EXISTS expenses_backup;
CREATE TABLE expenses_backup AS SELECT * FROM expenses;

-- Step 4: Verify backup was created
SELECT COUNT(*) as backup_count FROM expenses_backup;

-- Step 5: Truncate the expenses table
-- WARNING: This will delete all existing expense records!
-- Make sure backup was created successfully before running this!
TRUNCATE TABLE expenses;

-- Step 6: Modify the id column to bigint with AUTO_INCREMENT
ALTER TABLE expenses 
MODIFY COLUMN id bigint NOT NULL AUTO_INCREMENT;

-- Step 7: Verify the change
DESCRIBE expenses;

-- Step 8: Verify table is empty
SELECT COUNT(*) as current_expenses FROM expenses;

-- ============================================================
-- VERIFICATION
-- ============================================================
-- You should see:
-- - expenses table: 0 records, id is bigint AUTO_INCREMENT
-- - expenses_backup table: has your old records
-- ============================================================

-- ============================================================
-- NOTES:
-- ============================================================
-- 1. This script DELETES all existing expense records
-- 2. A backup is created in expenses_backup table
-- 3. After running this:
--    a) Upload the updated Django model files
--    b) Restart the application in cPanel
--    c) Test by creating a new expense
-- ============================================================
