-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtool.py
78 lines (71 loc) · 2.78 KB
/
tool.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sqlite3 as sql
conn = sql.connect("database.db")
curr = conn.cursor()
curr.execute('''
PRAGMA foreign_key = ON
''')
curr.execute('''create table USERS (
user_id integer primary key autoincrement,
name text not null,
email text not null unique,
password text not null,
total_balance integer default 0,
unapproved_balance integer default 0,
approved_balance integer default 0,
friends text default ",")''')
curr.execute('''create table TRANSACTIONS (
transaction_id integer primary key autoincrement,
title text not null,
amount int not null,
comment text,
status int default 0,
sender_id integer not null,
receiver_id integer not null,
FOREIGN KEY(sender_id)
REFERENCES USERS(user_id)
FOREIGN KEY(receiver_id)
REFERENCES USERS(user_id)
)''')
curr.execute('''create table GROUPS(
group_id integer primary key autoincrement,
creator_id integer,
name text not null
)''')
curr.execute('''create table MEMEBERSHIP(
group_id integer not null,
user_id integer not null,
amount integer default 0,
FOREIGN KEY(user_id)
REFERENCES USERS(user_id)
FOREIGN KEY(group_id)
REFERENCES GROUPS(group_id)
UNIQUE('group_id', 'user_id')
)''')
curr.execute('''create table GROUPTRANSACTIONS(
groupTransaction_id integer primary key autoincrement,
title text not null,
group_id integer not null,
amount integer default 0,
FOREIGN KEY(group_id)
REFERENCES GROUPS(group_id)
)''')
curr.execute('''create table GROUPTRANSACTIONS_PAYERS(
groupTransaction_id integer not null,
payer_id integer not null,
amount integer default 0,
FOREIGN KEY(payer_id)
REFERENCES USERS(user_id)
FOREIGN KEY(groupTransaction_id)
REFERENCES GROUPTRANSACTIONS(groupTransaction_id)
)''')
curr.execute('''create table SHARES(
share integer not null default 1,
user_id integer not null,
groupTransaction_id integer not null,
FOREIGN KEY(user_id)
REFERENCES USERS(user_id)
FOREIGN KEY(groupTransaction_id)
REFERENCES GROUPTRANSACTIONS(groupTransaction_id)
UNIQUE ('groupTransaction_id','user_id')
)''')
curr.close()