/**
* Migration: Backfill FullTextIndex for accounting entities
*
* Accounts und FiscalYears wurden bisher ohne FullTextIndex angelegt,
* weil die accounting-backend Services (accountService, fiscalYearService)
* die Spalte nicht befuellt haben.
*
* Dadurch findet MATCH...AGAINST auf ObjectBase.FullTextIndex
* diese Eintraege nicht, da der Wert NULL ist.
*
* Diese Migration setzt FullTextIndex auf den Display-Wert fuer:
* - Type = 'account' (Display = "1200 - Kassenbestand")
* - Type = 'fiscalyear' (Display = "2025")
* - Type = 'costcenter' (Display der Group/Event)
*/
export const id = '20260619-backfill-accounting-fulltext';
export const name = 'Backfill FullTextIndex for accounting entities (account, fiscalyear, costcenter)';
/**
* @param {{ query: Function }} api
*/
export const migrate = async ({ query }) => {
await query(`SET @@session.system_versioning_alter_history = KEEP`, []);
// Accounts: FullTextIndex = Display (enthält "Nummer - Name")
await query(`
UPDATE ObjectBase
SET FullTextIndex = Display
WHERE Type IN ('account', 'fiscalyear')
AND (FullTextIndex IS NULL OR FullTextIndex = '')
`, []);
// CostCenter (groups/events/locations): FullTextIndex = CONCAT(Title, ' ', Display)
await query(`
UPDATE ObjectBase
SET FullTextIndex = CONCAT(IFNULL(Title, ''), ' ', IFNULL(Display, ''))
WHERE Type IN ('group', 'event', 'location')
AND (FullTextIndex IS NULL OR FullTextIndex = '')
`, []);
};