18 lines
1.1 KiB
MySQL
18 lines
1.1 KiB
MySQL
|
|
-- Only customer defaults change; existing order/facture lines are untouched.
|
||
|
|
-- 49.00 was the legacy default, not a stored indication of a negotiated price.
|
||
|
|
ALTER TABLE customers ADD COLUMN IF NOT EXISTS invoice_fee_exempt BOOLEAN NOT NULL DEFAULT FALSE;
|
||
|
|
ALTER TABLE customers ALTER COLUMN invoice_fee_amount DROP NOT NULL;
|
||
|
|
ALTER TABLE customers ALTER COLUMN invoice_fee_amount DROP DEFAULT;
|
||
|
|
-- One-time conversion, guarded against reruns by the setting row.
|
||
|
|
DO $$ BEGIN
|
||
|
|
IF NOT EXISTS (SELECT 1 FROM settings WHERE key = 'invoice_fee_product_id') THEN
|
||
|
|
UPDATE customers SET invoice_fee_exempt = TRUE WHERE invoice_fee_amount = 0;
|
||
|
|
UPDATE customers SET invoice_fee_amount = NULL WHERE invoice_fee_amount = 49.00;
|
||
|
|
END IF;
|
||
|
|
END $$;
|
||
|
|
INSERT INTO settings (key, value, category, description, value_type, is_public)
|
||
|
|
VALUES ('invoice_fee_product_id', '', 'system', 'Standardvare til faktureringsgebyr', 'string', TRUE)
|
||
|
|
ON CONFLICT (key) DO NOTHING;
|
||
|
|
ALTER TABLE tmodule_order_lines ADD COLUMN IF NOT EXISTS source_type TEXT;
|
||
|
|
ALTER TABLE tmodule_order_lines ADD COLUMN IF NOT EXISTS product_id INTEGER REFERENCES products(id);
|