fix invoice number
This commit is contained in:
@@ -3,7 +3,20 @@ import { Migration } from '@mikro-orm/migrations';
|
||||
export class Migration20260516121012 extends Migration {
|
||||
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(`alter table "invoice_items" add column "sub_total" int generated always as (COALESCE(unit_price, 0) * quantity) STORED not null, add column "total" int generated always as ((COALESCE(unit_price, 0) * quantity) - COALESCE(discount, 0)) STORED not null;`);
|
||||
this.addSql(`
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "invoice_items"
|
||||
ADD COLUMN "sub_total" int GENERATED ALWAYS AS (COALESCE(unit_price, 0) * quantity) STORED NOT NULL,
|
||||
ADD COLUMN "total" int GENERATED ALWAYS AS ((COALESCE(unit_price, 0) * quantity) - COALESCE(discount, 0)) STORED NOT NULL;
|
||||
EXCEPTION
|
||||
WHEN duplicate_column THEN NULL;
|
||||
END $$;
|
||||
`);
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(`alter table "invoice_items" drop column if exists "sub_total";`);
|
||||
this.addSql(`alter table "invoice_items" drop column if exists "total";`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user