Files
negareh-api/database/migrations/Migration20260626150000.ts
T
2026-06-26 13:24:52 +03:30

37 lines
1011 B
TypeScript

import { Migration } from '@mikro-orm/migrations';
export class Migration20260626150000 extends Migration {
override async up(): Promise<void> {
this.addSql(`DROP TRIGGER IF EXISTS trg_invoice_items_recalc ON invoice_items;`);
this.addSql(`
CREATE TRIGGER trg_invoice_items_recalc
AFTER INSERT OR UPDATE OR DELETE
ON invoice_items
FOR EACH ROW
EXECUTE FUNCTION recalc_invoice_totals();
`);
this.addSql(`DROP TRIGGER IF EXISTS trg_payments_recalc ON payments;`);
this.addSql(`
CREATE TRIGGER trg_payments_recalc
AFTER INSERT OR UPDATE OR DELETE
ON payments
FOR EACH ROW
EXECUTE FUNCTION recalc_invoice_payments();
`);
this.addSql(`
UPDATE invoice_items
SET quantity = quantity
WHERE deleted_at IS NULL;
`);
}
override async down(): Promise<void> {
this.addSql(`DROP TRIGGER IF EXISTS trg_invoice_items_recalc ON invoice_items;`);
this.addSql(`DROP TRIGGER IF EXISTS trg_payments_recalc ON payments;`);
}
}