Merge dev into production release without education
This commit is contained in:
commit
fc541f024d
50 files changed
+2986
-458
No files matched your search
@@ -269,7 +269,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
|
||||
@@ -416,6 +418,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,
|
||||
@@ -446,6 +451,17 @@ export const ensureSchema = async (database: DatabaseClient = db) => {
|
||||
UNIQUE (bird_id, recorded_on)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS weight_reminder_deliveries (
|
||||
bird_id UUID NOT NULL REFERENCES birds(id) ON DELETE CASCADE,
|
||||
workspace_id INTEGER NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
|
||||
activity_at TIMESTAMPTZ NOT NULL,
|
||||
recipient TEXT NOT NULL,
|
||||
claim_token UUID NOT NULL,
|
||||
claimed_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
delivered_at TIMESTAMPTZ,
|
||||
PRIMARY KEY (bird_id, workspace_id, activity_at, recipient)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS vet_visits (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
bird_id UUID NOT NULL REFERENCES birds(id) ON DELETE CASCADE,
|
||||
@@ -549,6 +565,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 (
|
||||
|
||||
Reference in new issue
Block a user