budget/scripts/create_table.sql
2023-05-28 12:07:16 +08:00

49 lines
1 KiB
SQL

-- 账户表
CREATE TABLE account (
a_id SERIAL PRIMARY KEY, -- 账户号
balance MONEY, -- 余额
meta JSONB -- 元数据
);
-- {"name":"name",
-- time:"2022-02-02",
-- “budget": [
-- {"time":"2022-02","value":20.32},
-- {"time":"2022-01","value":30.32}
-- ]
-- "discription":"something"}
-- 类别表
CREATE TABLE category (
c_id SERIAL PRIMARY KEY, -- 类别号
meta JSONB -- 元数据
);
-- {"name":"name",
-- "type":"in"/"out",
-- “budget": [
-- {"time":"2022-02","value":20.32},
-- {"time":"2022-01","value":30.32}
-- ]
-- "discription":"something"}
-- 流水表
CREATE TABLE transaction (
t_id SERIAL PRIMARY KEY, -- 流水号
c_id INTEGER REFERENCES category(c_id), -- 关联类别号
a_id INTEGER REFERENCES account(a_id), -- 关联账户号
s_id INTEGER REFERENCES category(c_id), -- 源账户号
amount MONEY,
meta JSONB -- 元数据
);
-- {"discription":"something",(可选)
-- "type":"in"/"out"/"transfer",
-- "reimburse":{ (报销)
-- "finish": true,
-- "ref":t_id
-- }
-- "":"something"}