DeclarationTVA/sql/migration_fix_account_mappings.sql
Frank Cools c74e09993f Add database debugging and fix schema for multiple accounts
Database Schema Fix:
- Fixed unique constraint to allow multiple accounts per CA-3 line
- Changed from (entity, ca3_line) to (entity, ca3_line, account_code)
- Added migration script to update existing tables
- Updated table comments to reflect new CA-3 line structure

Debug Features Added:
- Database operation logging in updateAccountMapping method
- Table existence and structure checking in setup page
- Detailed error logging for SQL operations
- Form data processing visibility

The issue was likely the unique constraint preventing multiple accounts per line!
2025-10-02 17:30:55 +02:00

22 lines
916 B
SQL

--
-- Migration script to fix account mappings table
-- Fixes the unique constraint to allow multiple accounts per CA-3 line
--
-- Drop the old unique constraint that prevents multiple accounts per line
ALTER TABLE `llx_declarationtva_account_mappings`
DROP INDEX `uk_mapping_entity_line`;
-- Add new unique constraint that allows multiple accounts per line
-- but prevents duplicate account mappings
ALTER TABLE `llx_declarationtva_account_mappings`
ADD UNIQUE KEY `uk_mapping_entity_line_account` (`entity`, `ca3_line`, `account_code`);
-- Add index on account_code for better performance
ALTER TABLE `llx_declarationtva_account_mappings`
ADD INDEX `idx_account_code` (`account_code`);
-- Update the comment to reflect the new structure
ALTER TABLE `llx_declarationtva_account_mappings`
MODIFY COLUMN `ca3_line` varchar(8) NOT NULL COMMENT 'A1, A2, A3, A4, A5, 08, 09, 9B, 17, 20, 21, 22, 25, 26, 28, 29';