Create finance__account table
CREATE TABLE finance__account (
id uuid PRIMARY KEY,
code varchar(32) NOT NULL,
name varchar(256) NOT NULL,
account_type varchar(16) NOT NULL,
description text,
active boolean NOT NULL DEFAULT true,
created_at timestamptz NOT NULL,
created_by varchar(128) NOT NULL,
updated_at timestamptz NOT NULL,
updated_by varchar(128) NOT NULL,
version bigint NOT NULL DEFAULT 0,
CONSTRAINT finance__account_type_check
CHECK (account_type IN ('ASSET', 'LIABILITY', 'EQUITY', 'REVENUE', 'EXPENSE'))
);
CREATE UNIQUE INDEX finance__account_code_uk
ON finance__account (code);
DROP TABLE finance__account;
Seed minimal chart of accounts
INSERT INTO finance__account (id, code, name, account_type, description, created_at, created_by, updated_at, updated_by)
VALUES
(gen_random_uuid(), '1100', 'Accounts Receivable', 'ASSET', 'Money owed to the company by customers', now(), '__seed__', now(), '__seed__'),
(gen_random_uuid(), '1200', 'Inventory', 'ASSET', 'Value of goods held in warehouses', now(), '__seed__', now(), '__seed__'),
(gen_random_uuid(), '1000', 'Cash', 'ASSET', 'Cash and bank balances', now(), '__seed__', now(), '__seed__'),
(gen_random_uuid(), '2100', 'Accounts Payable', 'LIABILITY', 'Money the company owes to suppliers', now(), '__seed__', now(), '__seed__'),
(gen_random_uuid(), '4100', 'Sales Revenue', 'REVENUE', 'Income from sales orders', now(), '__seed__', now(), '__seed__'),
(gen_random_uuid(), '5100', 'Cost of Goods Sold', 'EXPENSE', 'Direct cost of goods delivered to customers', now(), '__seed__', now(), '__seed__');
DELETE FROM finance__account WHERE created_by = '__seed__';