003-finance-accounts.xml
3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd">
<!--
pbc-finance v0.30 — Chart of accounts.
Adds the finance__account table and seeds a minimal 6-account
chart covering the accounts the event subscribers reference:
AR, AP, Revenue, COGS, Inventory, Cash.
Operators can add accounts via POST /api/v1/finance/accounts
or through the SPA. The seeded set is NOT a full chart — it's
the minimum needed for the existing AR/AP event-driven journal
entries to reference real accounts. A richer default chart
(sub-accounts, account groups) is a future enhancement.
-->
<changeSet id="finance-accounts-001" author="vibe_erp">
<comment>Create finance__account table</comment>
<sql>
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);
</sql>
<rollback>
DROP TABLE finance__account;
</rollback>
</changeSet>
<changeSet id="finance-accounts-002-seed" author="vibe_erp">
<comment>Seed minimal chart of accounts</comment>
<sql>
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__');
</sql>
<rollback>
DELETE FROM finance__account WHERE created_by = '__seed__';
</rollback>
</changeSet>
</databaseChangeLog>