feat: add reference tables schema and Pydantic models
Implements Step 1.4: Creates migration for species, locations, products, feed_types, and users tables with full CHECK constraints. Adds Pydantic models with validation for all reference types including enums for ProductUnit and UserRole. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
52
migrations/0001-reference-tables.sql
Normal file
52
migrations/0001-reference-tables.sql
Normal file
@@ -0,0 +1,52 @@
|
||||
-- ABOUTME: Migration 0001 - reference-tables
|
||||
-- ABOUTME: Creates the five reference tables: species, locations, products, feed_types, users.
|
||||
|
||||
-- Species: lookup table for animal species (duck, goose, sheep)
|
||||
CREATE TABLE species (
|
||||
code TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
active INTEGER NOT NULL DEFAULT 1 CHECK(active IN (0, 1)),
|
||||
created_at_utc INTEGER NOT NULL,
|
||||
updated_at_utc INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- Locations: physical locations (Strip 1-4, Nursery 1-4)
|
||||
CREATE TABLE locations (
|
||||
id TEXT PRIMARY KEY CHECK(length(id) = 26),
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
active INTEGER NOT NULL DEFAULT 1 CHECK(active IN (0, 1)),
|
||||
created_at_utc INTEGER NOT NULL,
|
||||
updated_at_utc INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- Products: things that can be collected/sold (eggs, meat, etc.)
|
||||
CREATE TABLE products (
|
||||
code TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
unit TEXT NOT NULL CHECK(unit IN ('piece', 'kg')),
|
||||
collectable INTEGER NOT NULL CHECK(collectable IN (0, 1)),
|
||||
sellable INTEGER NOT NULL CHECK(sellable IN (0, 1)),
|
||||
active INTEGER NOT NULL DEFAULT 1 CHECK(active IN (0, 1)),
|
||||
created_at_utc INTEGER NOT NULL,
|
||||
updated_at_utc INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- Feed types: types of feed (starter, grower, layer)
|
||||
CREATE TABLE feed_types (
|
||||
code TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
default_bag_size_kg INTEGER NOT NULL CHECK(default_bag_size_kg >= 1),
|
||||
protein_pct REAL NULL,
|
||||
active INTEGER NOT NULL DEFAULT 1 CHECK(active IN (0, 1)),
|
||||
created_at_utc INTEGER NOT NULL,
|
||||
updated_at_utc INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- Users: system users with roles
|
||||
CREATE TABLE users (
|
||||
username TEXT PRIMARY KEY,
|
||||
role TEXT NOT NULL CHECK(role IN ('admin', 'recorder')),
|
||||
active INTEGER NOT NULL DEFAULT 1 CHECK(active IN (0, 1)),
|
||||
created_at_utc INTEGER NOT NULL,
|
||||
updated_at_utc INTEGER NOT NULL
|
||||
);
|
||||
Reference in New Issue
Block a user