Added behavior journal, adjusted layout, and added some colors
Deploy / deploy-prod (push) Skipped
Deploy / deploy-dev (push) Successful in 4m18s

This commit is contained in:
Corey Blais committed 2026-10-05 15:20:00 -04:00
1 parent b1b89ad334
commit 3237cd7601
31 files changed
+2135 -275

No files matched your search

+37 -1
View File
@@ -303,7 +303,9 @@ export const ensureSchema = async (database: DatabaseClient = db) => {
ADD COLUMN IF NOT EXISTS notify_on_memorial_day BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE birds
ALTER COLUMN tag_id DROP NOT NULL;
ALTER COLUMN tag_id DROP NOT NULL,
ALTER COLUMN workspace_id DROP NOT NULL,
ALTER COLUMN workspace_id DROP DEFAULT;
UPDATE birds
SET tag_id = NULL
@@ -450,6 +452,9 @@ export const ensureSchema = async (database: DatabaseClient = db) => {
ON flock_notes (bird_id, updated_at DESC)
WHERE bird_id IS NOT NULL;
-- Bird-specific notes remain attached while their bird is between flocks.
ALTER TABLE flock_notes ALTER COLUMN workspace_id DROP NOT NULL;
CREATE TABLE IF NOT EXISTS audit_log_entries (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
workspace_id INTEGER NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
@@ -594,6 +599,37 @@ export const ensureSchema = async (database: DatabaseClient = db) => {
CREATE INDEX IF NOT EXISTS idx_medication_administrations_medication_date
ON medication_administrations (medication_id, administered_on DESC, created_at DESC);
CREATE TABLE IF NOT EXISTS behavior_types (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
workspace_id INTEGER REFERENCES workspaces(id) ON DELETE SET NULL,
name VARCHAR(120) NOT NULL,
is_default BOOLEAN NOT NULL DEFAULT FALSE,
description TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_behavior_types_workspace_name
ON behavior_types (workspace_id, lower(name)) WHERE workspace_id IS NOT NULL;
CREATE UNIQUE INDEX IF NOT EXISTS idx_behavior_types_default_name
ON behavior_types (lower(name)) WHERE is_default;
INSERT INTO behavior_types (name, is_default) VALUES
('Screaming / vocalization', TRUE), ('Biting / aggression', TRUE), ('Feather plucking', TRUE),
('Repetitive behavior', TRUE), ('Excessive scratching', TRUE), ('Hiding / withdrawal', TRUE),
('Unusual posture', TRUE), ('Food refusal', TRUE), ('Other', TRUE)
ON CONFLICT DO NOTHING;
CREATE TABLE IF NOT EXISTS behavior_occurrences (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
bird_id UUID NOT NULL REFERENCES birds(id) ON DELETE CASCADE,
behavior_type_id UUID NOT NULL REFERENCES behavior_types(id),
occurred_at TIMESTAMPTZ NOT NULL,
duration_seconds DOUBLE PRECISION CHECK (duration_seconds > 0 AND duration_seconds <= 31536000),
severity SMALLINT CHECK (severity BETWEEN 1 AND 5),
notes TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_behavior_occurrences_bird_time ON behavior_occurrences (bird_id, occurred_at DESC);
CREATE INDEX IF NOT EXISTS idx_behavior_occurrences_bird_type_time ON behavior_occurrences (bird_id, behavior_type_id, occurred_at DESC);
DO $$
BEGIN
IF EXISTS (