update migrations 2

This commit is contained in:
Flatlogic Bot 2026-04-13 05:45:19 +00:00
parent d30d6e9725
commit 063006a6a2

View File

@ -1,23 +1,25 @@
-- Add account_id to expense_categories
-- We rely on the migration runner's exception handling to skip if the column or constraint already exists
ALTER TABLE expense_categories ADD COLUMN account_id INT DEFAULT NULL;
ALTER TABLE expense_categories ADD CONSTRAINT fk_expense_category_account FOREIGN KEY (account_id) REFERENCES accounting_accounts(id) ON DELETE SET NULL;
-- Seed default mappings (Best effort based on Arabic account names vs English categories)
-- Accounts:
-- 13: مصروفات الرواتب (Salaries)
-- 16: مصروفات التسويق (Marketing)
-- 30: مصروفات الإيجار (Rent)
-- 31: مصروفات المرافق (Utilities)
-- 12: تكلفة البضاعة المباعة (COGS)
-- Seed default mappings using subqueries instead of hardcoded IDs.
-- The accounts are inserted by seed_accounts.php which uses Arabic names.
-- Update 'Salaries' category
UPDATE expense_categories SET account_id = 13 WHERE name LIKE '%Salaries%' OR name LIKE '%رواتب%';
UPDATE expense_categories
SET account_id = (SELECT id FROM accounting_accounts WHERE name LIKE '%مصروفات الرواتب%' LIMIT 1)
WHERE name LIKE '%Salaries%' OR name LIKE '%رواتب%';
-- Update 'Rent' category
UPDATE expense_categories SET account_id = 30 WHERE name LIKE '%Rent%' OR name LIKE '%إيجار%';
UPDATE expense_categories
SET account_id = (SELECT id FROM accounting_accounts WHERE name LIKE '%مصروفات الإيجار%' LIMIT 1)
WHERE name LIKE '%Rent%' OR name LIKE '%إيجار%';
-- Update 'Utilities' category
UPDATE expense_categories SET account_id = 31 WHERE name LIKE '%Utilities%' OR name LIKE '%مرافق%';
UPDATE expense_categories
SET account_id = (SELECT id FROM accounting_accounts WHERE name LIKE '%مصروفات المرافق%' LIMIT 1)
WHERE name LIKE '%Utilities%' OR name LIKE '%مرافق%';
-- Update 'Advertising' category
UPDATE expense_categories SET account_id = 16 WHERE name LIKE '%Advertising%' OR name LIKE '%Marketing%' OR name LIKE '%تسو%';
UPDATE expense_categories
SET account_id = (SELECT id FROM accounting_accounts WHERE name LIKE '%مصروفات التسويق%' LIMIT 1)
WHERE name LIKE '%Advertising%' OR name LIKE '%Marketing%' OR name LIKE '%تسو%';