-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sql
More file actions
35 lines (32 loc) · 995 Bytes
/
init.sql
File metadata and controls
35 lines (32 loc) · 995 Bytes
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
-- Criação da tabela products
CREATE TABLE IF NOT EXISTS products (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
price DECIMAL NOT NULL,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
-- Criação da tabela tables
CREATE TABLE IF NOT EXISTS tables (
id SERIAL PRIMARY KEY,
table_number INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
-- Criação da tabela tables_sessions
CREATE TABLE IF NOT EXISTS tables_sessions (
id SERIAL PRIMARY KEY,
table_id INTEGER NOT NULL REFERENCES tables(id),
opened_at TIMESTAMP DEFAULT NOW(),
closed_at TIMESTAMP
);
-- Criação da tabela orders
CREATE TABLE IF NOT EXISTS orders (
id SERIAL PRIMARY KEY,
table_session_id INTEGER NOT NULL REFERENCES tables_sessions(id),
product_id INTEGER NOT NULL REFERENCES products(id),
quantity INTEGER NOT NULL,
price DECIMAL NOT NULL,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);