-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
30 lines (26 loc) · 979 Bytes
/
schema.sql
File metadata and controls
30 lines (26 loc) · 979 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
-- =============================================================
-- Section 17 — Functions, Stored Procedures, and Triggers
-- =============================================================
DROP SCHEMA IF EXISTS adv_funcs CASCADE;
CREATE SCHEMA adv_funcs;
SET search_path TO adv_funcs;
CREATE TABLE account (
id SERIAL PRIMARY KEY,
holder VARCHAR(100) NOT NULL,
balance INTEGER NOT NULL CHECK (balance >= 0)
);
CREATE TABLE product (
id SERIAL PRIMARY KEY,
name VARCHAR(200) NOT NULL,
price_cents INTEGER NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Audit log populated by a trigger in the exercises
CREATE TABLE product_audit (
id SERIAL PRIMARY KEY,
product_id INTEGER NOT NULL,
changed_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
action CHAR(1) NOT NULL, -- I / U / D
old_price_cents INTEGER,
new_price_cents INTEGER
);