Add invoice bank account templates API and migration.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-09-21 23:31:58 +03:30
co-authored by Cursor
parent 503b70a690
commit 2a01873c95
5 changed files with 390 additions and 0 deletions
@@ -0,0 +1,27 @@
-- Reusable bank account templates (platform or business), parallel to invoice_item_templates.
CREATE TABLE IF NOT EXISTS invoice_account_templates (
id BIGSERIAL PRIMARY KEY,
owner_scope invoice_owner_scope NOT NULL,
business_id BIGINT NULL REFERENCES businesses (id) ON DELETE CASCADE ON UPDATE NO ACTION,
bank_name VARCHAR(255) NOT NULL,
account_holder_name VARCHAR(255) NULL,
card_number VARCHAR(64) NULL,
iban VARCHAR(64) NULL,
sort_order INT NOT NULL DEFAULT 0,
is_active BOOLEAN NOT NULL DEFAULT TRUE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_invoice_account_templates_owner_scope
ON invoice_account_templates (owner_scope, sort_order);
CREATE INDEX IF NOT EXISTS idx_invoice_account_templates_business_id
ON invoice_account_templates (business_id);
DROP TRIGGER IF EXISTS invoice_account_templates_set_updated_at ON invoice_account_templates;
CREATE TRIGGER invoice_account_templates_set_updated_at
BEFORE UPDATE ON invoice_account_templates
FOR EACH ROW
EXECUTE FUNCTION set_updated_at();