From 6536cb91269ba5655dffd49c9890c39515cd7892 Mon Sep 17 00:00:00 2001 From: iridiumR Date: Sun, 28 May 2023 12:07:16 +0800 Subject: [PATCH] feat: update table --- scripts/create_table.sql | 21 ++++++++------------- scripts/drop_table.sql | 1 - src/budget/_account.py | 4 ++-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/scripts/create_table.sql b/scripts/create_table.sql index 4e633ff..e9c3aa3 100644 --- a/scripts/create_table.sql +++ b/scripts/create_table.sql @@ -1,10 +1,11 @@ -- 账户表 CREATE TABLE account ( - a_id SERIAL PRIMARY KEY, --账户号 - meta JSONB -- 元数据 + a_id SERIAL PRIMARY KEY, -- 账户号 + balance MONEY, -- 余额 + meta JSONB -- 元数据 ); -- {"name":"name", --- "balance": 0.00, +-- time:"2022-02-02", -- “budget": [ -- {"time":"2022-02","value":20.32}, -- {"time":"2022-01","value":30.32} @@ -27,27 +28,21 @@ CREATE TABLE category ( -- 流水表 CREATE TABLE transaction ( t_id SERIAL PRIMARY KEY, -- 流水号 - c_id INTEGER REFERENCES category(c_id), -- 关联账户号 - a_id INTEGER REFERENCES account(a_id), -- 关联类别号 + 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", --- "transfer_dist":a_id,(可选) -- "reimburse":{ (报销) -- "finish": true, -- "ref":t_id -- } -- "":"something"} --- 转账表 记录转账信息 -CREATE TABLE account_transaction( - at_id SERIAL PRIMARY KEY, -- 转账号 - src INTEGER REFERENCES category(c_id), -- 源账户号 - dst INTEGER REFERENCES category(c_id), -- 目的账户号 - meta JSONB -- 元数据 -); diff --git a/scripts/drop_table.sql b/scripts/drop_table.sql index 92d280d..00af04d 100644 --- a/scripts/drop_table.sql +++ b/scripts/drop_table.sql @@ -1,5 +1,4 @@ DROP TABLE transaction; -DROP TABLE account_transaction; DROP TABLE category; DROP TABLE account; diff --git a/src/budget/_account.py b/src/budget/_account.py index 6d3f6e5..5e29524 100644 --- a/src/budget/_account.py +++ b/src/budget/_account.py @@ -195,11 +195,11 @@ class AccountTab(TabPage): raise Exception('Account name cannot be empty') # JSONB插入数据 - data = {"name": line1.text(), "balance": balance, "description": description} + data = {"name": line1.text(), "description": description} data = json.dumps(data) print("insert data:",data) - self.pg.execute("INSERT INTO account (meta) VALUES (%s)", (data,)) + self.pg.execute("INSERT INTO account (balance, meta) VALUES (%s, %s)", (balance, data,)) # 刷新表格 self.selected()