chore: normalize line endings to LF

This commit is contained in:
Matt Johnson 2026-05-16 21:27:30 +00:00
commit 374a8c067f
26 changed files with 5357 additions and 5346 deletions

View file

@ -1,64 +1,64 @@
-- Migration: 001_create_config_schema
-- Creates the config schema with adapters and api_keys tables.
-- Also seeds the NWS adapter row from current TOML config.
-- Create config schema
CREATE SCHEMA config;
-- Adapters configuration table
CREATE TABLE config.adapters (
name TEXT PRIMARY KEY,
enabled BOOLEAN NOT NULL DEFAULT true,
cadence_s INTEGER NOT NULL,
settings JSONB NOT NULL DEFAULT '{}'::jsonb,
paused_at TIMESTAMPTZ,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- API keys table (encrypted values)
CREATE TABLE config.api_keys (
alias TEXT PRIMARY KEY,
encrypted_value BYTEA NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
rotated_at TIMESTAMPTZ,
last_used_at TIMESTAMPTZ
);
-- Notify function for config changes
CREATE OR REPLACE FUNCTION config.notify_config_change()
RETURNS trigger AS $$
DECLARE
key_value TEXT;
BEGIN
-- Handle different table structures
IF TG_TABLE_NAME = 'adapters' THEN
key_value := COALESCE(NEW.name, OLD.name, '');
ELSIF TG_TABLE_NAME = 'api_keys' THEN
key_value := COALESCE(NEW.alias, OLD.alias, '');
ELSE
key_value := '';
END IF;
PERFORM pg_notify('config_changed', TG_TABLE_NAME || ':' || key_value);
RETURN COALESCE(NEW, OLD);
END;
$$ LANGUAGE plpgsql;
-- Trigger for adapters table
CREATE TRIGGER adapters_notify
AFTER INSERT OR UPDATE OR DELETE ON config.adapters
FOR EACH ROW EXECUTE FUNCTION config.notify_config_change();
-- Trigger for api_keys table
CREATE TRIGGER api_keys_notify
AFTER INSERT OR UPDATE OR DELETE ON config.api_keys
FOR EACH ROW EXECUTE FUNCTION config.notify_config_change();
-- Seed NWS adapter from current TOML config values
INSERT INTO config.adapters (name, enabled, cadence_s, settings)
VALUES (
'nws',
true,
60,
'{"states": ["ID", "OR", "WA", "MT", "WY", "UT", "NV"], "contact_email": "mj@k7zvx.com"}'::jsonb
);
-- Migration: 001_create_config_schema
-- Creates the config schema with adapters and api_keys tables.
-- Also seeds the NWS adapter row from current TOML config.
-- Create config schema
CREATE SCHEMA config;
-- Adapters configuration table
CREATE TABLE config.adapters (
name TEXT PRIMARY KEY,
enabled BOOLEAN NOT NULL DEFAULT true,
cadence_s INTEGER NOT NULL,
settings JSONB NOT NULL DEFAULT '{}'::jsonb,
paused_at TIMESTAMPTZ,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- API keys table (encrypted values)
CREATE TABLE config.api_keys (
alias TEXT PRIMARY KEY,
encrypted_value BYTEA NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
rotated_at TIMESTAMPTZ,
last_used_at TIMESTAMPTZ
);
-- Notify function for config changes
CREATE OR REPLACE FUNCTION config.notify_config_change()
RETURNS trigger AS $$
DECLARE
key_value TEXT;
BEGIN
-- Handle different table structures
IF TG_TABLE_NAME = 'adapters' THEN
key_value := COALESCE(NEW.name, OLD.name, '');
ELSIF TG_TABLE_NAME = 'api_keys' THEN
key_value := COALESCE(NEW.alias, OLD.alias, '');
ELSE
key_value := '';
END IF;
PERFORM pg_notify('config_changed', TG_TABLE_NAME || ':' || key_value);
RETURN COALESCE(NEW, OLD);
END;
$$ LANGUAGE plpgsql;
-- Trigger for adapters table
CREATE TRIGGER adapters_notify
AFTER INSERT OR UPDATE OR DELETE ON config.adapters
FOR EACH ROW EXECUTE FUNCTION config.notify_config_change();
-- Trigger for api_keys table
CREATE TRIGGER api_keys_notify
AFTER INSERT OR UPDATE OR DELETE ON config.api_keys
FOR EACH ROW EXECUTE FUNCTION config.notify_config_change();
-- Seed NWS adapter from current TOML config values
INSERT INTO config.adapters (name, enabled, cadence_s, settings)
VALUES (
'nws',
true,
60,
'{"states": ["ID", "OR", "WA", "MT", "WY", "UT", "NV"], "contact_email": "mj@k7zvx.com"}'::jsonb
);

View file

@ -1,46 +1,46 @@
-- Migration: 003_add_streams_table
-- Creates the config.streams table for JetStream stream retention configuration.
-- Uses column-filtered NOTIFY to prevent self-loop when supervisor updates max_bytes.
-- Streams configuration table
CREATE TABLE config.streams (
name TEXT PRIMARY KEY,
max_age_s BIGINT NOT NULL,
max_bytes BIGINT NOT NULL DEFAULT 1073741824, -- 1GB default
managed_max_bytes BOOLEAN NOT NULL DEFAULT true,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- Auto-update trigger for updated_at
CREATE TRIGGER streams_set_updated_at
BEFORE UPDATE ON config.streams
FOR EACH ROW EXECUTE FUNCTION config.set_updated_at();
-- Column-filtered NOTIFY trigger for streams.
-- Fires on INSERT/DELETE always.
-- On UPDATE, only fires when max_age_s changes (operator-touchable field),
-- NOT when max_bytes changes (supervisor-managed), to prevent recompute loop.
CREATE OR REPLACE FUNCTION config.notify_streams_change()
RETURNS trigger AS $$
BEGIN
IF TG_OP = 'INSERT' OR TG_OP = 'DELETE' THEN
PERFORM pg_notify('config_changed', 'streams:' ||
COALESCE(NEW.name, OLD.name));
ELSIF TG_OP = 'UPDATE' AND
OLD.max_age_s IS DISTINCT FROM NEW.max_age_s THEN
PERFORM pg_notify('config_changed', 'streams:' || NEW.name);
END IF;
RETURN COALESCE(NEW, OLD);
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER streams_notify
AFTER INSERT OR UPDATE OR DELETE ON config.streams
FOR EACH ROW EXECUTE FUNCTION config.notify_streams_change();
-- Seed with current stream values from investigation
-- CENTRAL_WX: 7d max_age (604800s), 10GB max_bytes (will be clamped to 6GB on first recompute)
-- CENTRAL_META: 1d max_age (86400s), 100MB max_bytes (will be raised to 1GB floor)
INSERT INTO config.streams (name, max_age_s, max_bytes) VALUES
('CENTRAL_WX', 604800, 10737418240),
('CENTRAL_META', 86400, 104857600);
-- Migration: 003_add_streams_table
-- Creates the config.streams table for JetStream stream retention configuration.
-- Uses column-filtered NOTIFY to prevent self-loop when supervisor updates max_bytes.
-- Streams configuration table
CREATE TABLE config.streams (
name TEXT PRIMARY KEY,
max_age_s BIGINT NOT NULL,
max_bytes BIGINT NOT NULL DEFAULT 1073741824, -- 1GB default
managed_max_bytes BOOLEAN NOT NULL DEFAULT true,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- Auto-update trigger for updated_at
CREATE TRIGGER streams_set_updated_at
BEFORE UPDATE ON config.streams
FOR EACH ROW EXECUTE FUNCTION config.set_updated_at();
-- Column-filtered NOTIFY trigger for streams.
-- Fires on INSERT/DELETE always.
-- On UPDATE, only fires when max_age_s changes (operator-touchable field),
-- NOT when max_bytes changes (supervisor-managed), to prevent recompute loop.
CREATE OR REPLACE FUNCTION config.notify_streams_change()
RETURNS trigger AS $$
BEGIN
IF TG_OP = 'INSERT' OR TG_OP = 'DELETE' THEN
PERFORM pg_notify('config_changed', 'streams:' ||
COALESCE(NEW.name, OLD.name));
ELSIF TG_OP = 'UPDATE' AND
OLD.max_age_s IS DISTINCT FROM NEW.max_age_s THEN
PERFORM pg_notify('config_changed', 'streams:' || NEW.name);
END IF;
RETURN COALESCE(NEW, OLD);
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER streams_notify
AFTER INSERT OR UPDATE OR DELETE ON config.streams
FOR EACH ROW EXECUTE FUNCTION config.notify_streams_change();
-- Seed with current stream values from investigation
-- CENTRAL_WX: 7d max_age (604800s), 10GB max_bytes (will be clamped to 6GB on first recompute)
-- CENTRAL_META: 1d max_age (86400s), 100MB max_bytes (will be raised to 1GB floor)
INSERT INTO config.streams (name, max_age_s, max_bytes) VALUES
('CENTRAL_WX', 604800, 10737418240),
('CENTRAL_META', 86400, 104857600);

View file

@ -1,11 +1,11 @@
-- Migration: 004_nws_states_to_bbox
-- Converts NWS adapter settings from states list to region bbox.
-- Bbox covers ID/OR/WA/MT/WY/UT/NV with buffer.
UPDATE config.adapters
SET settings = jsonb_set(
settings - 'states', -- Remove states key
'{region}',
'{"north": 49.5, "south": 31.0, "east": -102.0, "west": -124.5}'::jsonb
)
WHERE name = 'nws';
-- Migration: 004_nws_states_to_bbox
-- Converts NWS adapter settings from states list to region bbox.
-- Bbox covers ID/OR/WA/MT/WY/UT/NV with buffer.
UPDATE config.adapters
SET settings = jsonb_set(
settings - 'states', -- Remove states key
'{region}',
'{"north": 49.5, "south": 31.0, "east": -102.0, "west": -124.5}'::jsonb
)
WHERE name = 'nws';