brewlog/migrations/0003_activities.sql
Jon Seager b5e91d9d0d
refactor(db): consolidate 21 migrations into 4 clean files
No production instances exist, so safe to rewrite from scratch.
Drops columns that were added then removed (notes, password_hash,
cup rating), standardises timestamp format and primary key style,
and creates all tables in their final form without incremental
ALTER TABLE churn.
2026-02-05 21:06:37 +00:00

42 lines
1.6 KiB
SQL

-- Brew, cafe, and cup tables
CREATE TABLE brews (
id INTEGER PRIMARY KEY,
bag_id INTEGER NOT NULL REFERENCES bags(id) ON DELETE CASCADE,
coffee_weight REAL NOT NULL,
grinder_id INTEGER NOT NULL REFERENCES gear(id) ON DELETE RESTRICT,
grind_setting REAL NOT NULL,
brewer_id INTEGER NOT NULL REFERENCES gear(id) ON DELETE RESTRICT,
filter_paper_id INTEGER REFERENCES gear(id) ON DELETE SET NULL,
water_volume INTEGER NOT NULL,
water_temp REAL NOT NULL,
quick_notes TEXT,
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
);
CREATE INDEX idx_brews_bag_id ON brews(bag_id);
CREATE INDEX idx_brews_created_at ON brews(created_at DESC);
CREATE TABLE cafes (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
slug TEXT NOT NULL,
city TEXT NOT NULL,
country TEXT NOT NULL,
latitude REAL NOT NULL,
longitude REAL NOT NULL,
website TEXT,
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
);
CREATE UNIQUE INDEX idx_cafes_slug ON cafes(slug);
CREATE TABLE cups (
id INTEGER PRIMARY KEY,
roast_id INTEGER NOT NULL REFERENCES roasts(id) ON DELETE RESTRICT,
cafe_id INTEGER NOT NULL REFERENCES cafes(id) ON DELETE RESTRICT,
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
);
CREATE INDEX idx_cups_roast_id ON cups(roast_id);
CREATE INDEX idx_cups_cafe_id ON cups(cafe_id);