-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
47 lines (42 loc) · 1.14 KB
/
schema.sql
File metadata and controls
47 lines (42 loc) · 1.14 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
-- products, invoices, and invoice items
DROP TABLE IF EXISTS products;
DROP TABLE IF EXISTS invoices;
DROP TABLE IF EXISTS invoice_items;
CREATE TABLE products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
price REAL NOT NULL,
image_url TEXT
);
CREATE TABLE invoices (
id INTEGER PRIMARY KEY AUTOINCREMENT,
customer TEXT,
total REAL,
created TEXT
);
CREATE TABLE invoice_items (
id INTEGER PRIMARY KEY AUTOINCREMENT,
invoice_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
quantity INTEGER NOT NULL,
price REAL NOT NULL,
FOREIGN KEY (invoice_id) REFERENCES invoices(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
CREATE TABLE payments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
invoice_id INTEGER NOT NULL,
amount REAL NOT NULL,
method TEXT,
note TEXT,
created TEXT,
FOREIGN KEY (invoice_id) REFERENCES invoices(id)
);
CREATE TABLE attachments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
invoice_id INTEGER NOT NULL,
filename TEXT NOT NULL,
filepath TEXT NOT NULL,
uploaded_at TEXT,
FOREIGN KEY (invoice_id) REFERENCES invoices(id)
);