feat: update table
This commit is contained in:
parent
69ddbeb799
commit
6536cb9126
3 changed files with 10 additions and 16 deletions
|
@ -1,10 +1,11 @@
|
||||||
-- 账户表
|
-- 账户表
|
||||||
CREATE TABLE account (
|
CREATE TABLE account (
|
||||||
a_id SERIAL PRIMARY KEY, --账户号
|
a_id SERIAL PRIMARY KEY, -- 账户号
|
||||||
meta JSONB -- 元数据
|
balance MONEY, -- 余额
|
||||||
|
meta JSONB -- 元数据
|
||||||
);
|
);
|
||||||
-- {"name":"name",
|
-- {"name":"name",
|
||||||
-- "balance": 0.00,
|
-- time:"2022-02-02",
|
||||||
-- “budget": [
|
-- “budget": [
|
||||||
-- {"time":"2022-02","value":20.32},
|
-- {"time":"2022-02","value":20.32},
|
||||||
-- {"time":"2022-01","value":30.32}
|
-- {"time":"2022-01","value":30.32}
|
||||||
|
@ -27,27 +28,21 @@ CREATE TABLE category (
|
||||||
-- 流水表
|
-- 流水表
|
||||||
CREATE TABLE transaction (
|
CREATE TABLE transaction (
|
||||||
t_id SERIAL PRIMARY KEY, -- 流水号
|
t_id SERIAL PRIMARY KEY, -- 流水号
|
||||||
c_id INTEGER REFERENCES category(c_id), -- 关联账户号
|
c_id INTEGER REFERENCES category(c_id), -- 关联类别号
|
||||||
a_id INTEGER REFERENCES account(a_id), -- 关联类别号
|
a_id INTEGER REFERENCES account(a_id), -- 关联账户号
|
||||||
|
s_id INTEGER REFERENCES category(c_id), -- 源账户号
|
||||||
|
amount MONEY,
|
||||||
meta JSONB -- 元数据
|
meta JSONB -- 元数据
|
||||||
);
|
);
|
||||||
-- {"discription":"something",(可选)
|
-- {"discription":"something",(可选)
|
||||||
-- "type":"in"/"out"/"transfer",
|
-- "type":"in"/"out"/"transfer",
|
||||||
|
|
||||||
-- "transfer_dist":a_id,(可选)
|
|
||||||
-- "reimburse":{ (报销)
|
-- "reimburse":{ (报销)
|
||||||
-- "finish": true,
|
-- "finish": true,
|
||||||
-- "ref":t_id
|
-- "ref":t_id
|
||||||
-- }
|
-- }
|
||||||
-- "":"something"}
|
-- "":"something"}
|
||||||
|
|
||||||
-- 转账表 记录转账信息
|
|
||||||
CREATE TABLE account_transaction(
|
|
||||||
at_id SERIAL PRIMARY KEY, -- 转账号
|
|
||||||
src INTEGER REFERENCES category(c_id), -- 源账户号
|
|
||||||
dst INTEGER REFERENCES category(c_id), -- 目的账户号
|
|
||||||
meta JSONB -- 元数据
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
DROP TABLE transaction;
|
DROP TABLE transaction;
|
||||||
DROP TABLE account_transaction;
|
|
||||||
DROP TABLE category;
|
DROP TABLE category;
|
||||||
DROP TABLE account;
|
DROP TABLE account;
|
||||||
|
|
||||||
|
|
|
@ -195,11 +195,11 @@ class AccountTab(TabPage):
|
||||||
raise Exception('Account name cannot be empty')
|
raise Exception('Account name cannot be empty')
|
||||||
|
|
||||||
# JSONB插入数据
|
# JSONB插入数据
|
||||||
data = {"name": line1.text(), "balance": balance, "description": description}
|
data = {"name": line1.text(), "description": description}
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
print("insert data:",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()
|
self.selected()
|
||||||
|
|
Loading…
Reference in a new issue