Six transactions implemented in Python + PostgreSQL with full ACID guarantees and reactive (cascading) foreign-key constraints.
| Table | Columns | Key |
|---|---|---|
| Product | prodid, name, price |
prodid |
| Depot | depid, addr, volume |
depid |
| Stock | prodid, depid, qty |
(prodid, depid) — FKs to Product and Depot, both ON DELETE CASCADE / ON UPDATE CASCADE |
- Delete product
p1fromProductandStock. - Delete depot
d1fromDepotandStock. - Rename product
p1→pp1inProductandStock. - Rename depot
d1→dd1inDepotandStock. - Add product
(p100, cd, 5)toProductand(p100, d2, 50)toStock. - Add depot
(d100, Chicago, 100)toDepotand(p1, d100, 100)toStock.
Each transaction is wrapped in a BEGIN ... COMMIT / ROLLBACK block — see
transactions.py. For 1–4 the code exposes both a reactive version
(relying on the cascade clauses) and a manual version (explicit Stock
update inside the same transaction).
- Atomicity —
commit()/rollback()intransactions._run. - Consistency — primary keys, foreign keys, and
NOT NULLinschema.sql. - Isolation —
SERIALIZABLEisolation level set indb.py. - Durability — PostgreSQL WAL.
# 1. Create the database
createdb pace_sql
# 2. Configure credentials
cp .env.example .env # then edit if needed
# 3. Install dependencies
pip install -r requirements.txt
# 4. Run
python demo.py # uses reactive (cascade) versions for T1–T4
python demo.py manual # uses explicit Stock updates for T1–T4The demo reloads schema.sql before each transaction so it can be run
repeatedly and the table state is always shown before and after.
| File | Purpose |
|---|---|
schema.sql |
DDL + seed data + reactive FK constraints |
db.py |
Connection helper (SERIALIZABLE isolation) |
transactions.py |
The six transactions, with helper _run |
demo.py |
Runs all six and prints table state before / after |