check / check (push) Waiting to run
A target's settings move from the per-type JSON string in targets.config to columns: url, headers, timeout_seconds, forward_query, archive_expiry and archive_rotation. A column a type does not use stays empty. headers holds the header map as JSON text through GORM's JSON serializer, and archive_expiry holds a time.Duration, 0 meaning never. The forms check each setting once, with the same refusals and messages, and the edit form is filled from the columns, so the per-type config structs, their parsers and the "could not be read" branches are gone. A delivery task carries the six settings in place of the JSON string; tests check that each copy into a task, and back out of one, keeps all six. Model: opus-5-5
96 lines
2.5 KiB
SQL
96 lines
2.5 KiB
SQL
-- Migration 001: the main database's schema. The models in
|
|
-- internal/database must agree with it.
|
|
|
|
CREATE TABLE settings (
|
|
"key" text,
|
|
value text NOT NULL,
|
|
PRIMARY KEY ("key")
|
|
);
|
|
|
|
CREATE TABLE users (
|
|
id uuid,
|
|
created_at datetime,
|
|
updated_at datetime,
|
|
deleted_at datetime,
|
|
username text NOT NULL,
|
|
password text NOT NULL,
|
|
PRIMARY KEY (id),
|
|
CONSTRAINT chk_users_username
|
|
CHECK (length(CAST(username AS BLOB)) <= 1024)
|
|
);
|
|
|
|
CREATE INDEX idx_users_deleted_at ON users (deleted_at);
|
|
CREATE UNIQUE INDEX idx_users_username ON users (username);
|
|
|
|
CREATE TABLE api_keys (
|
|
id uuid,
|
|
created_at datetime,
|
|
updated_at datetime,
|
|
deleted_at datetime,
|
|
user_id uuid NOT NULL,
|
|
"key" text NOT NULL,
|
|
description text,
|
|
last_used_at datetime,
|
|
PRIMARY KEY (id),
|
|
CONSTRAINT fk_users_api_keys FOREIGN KEY (user_id) REFERENCES users (id)
|
|
);
|
|
|
|
CREATE INDEX idx_api_keys_deleted_at ON api_keys (deleted_at);
|
|
CREATE UNIQUE INDEX idx_api_keys_key ON api_keys ("key");
|
|
|
|
CREATE TABLE webhooks (
|
|
id uuid,
|
|
created_at datetime,
|
|
updated_at datetime,
|
|
deleted_at datetime,
|
|
user_id uuid NOT NULL,
|
|
name text NOT NULL,
|
|
description text,
|
|
retention_days integer,
|
|
PRIMARY KEY (id),
|
|
CONSTRAINT fk_users_webhooks FOREIGN KEY (user_id) REFERENCES users (id)
|
|
);
|
|
|
|
CREATE INDEX idx_webhooks_deleted_at ON webhooks (deleted_at);
|
|
|
|
CREATE TABLE entrypoints (
|
|
id uuid,
|
|
created_at datetime,
|
|
updated_at datetime,
|
|
deleted_at datetime,
|
|
webhook_id uuid NOT NULL,
|
|
path text NOT NULL,
|
|
description text,
|
|
active numeric DEFAULT true,
|
|
PRIMARY KEY (id),
|
|
CONSTRAINT fk_webhooks_entrypoints
|
|
FOREIGN KEY (webhook_id) REFERENCES webhooks (id)
|
|
);
|
|
|
|
CREATE INDEX idx_entrypoints_deleted_at ON entrypoints (deleted_at);
|
|
CREATE UNIQUE INDEX idx_entrypoints_path ON entrypoints (path);
|
|
|
|
CREATE TABLE targets (
|
|
id uuid,
|
|
created_at datetime,
|
|
updated_at datetime,
|
|
deleted_at datetime,
|
|
webhook_id uuid NOT NULL,
|
|
name text NOT NULL,
|
|
type text NOT NULL,
|
|
active numeric DEFAULT true,
|
|
url text,
|
|
headers text,
|
|
timeout_seconds integer,
|
|
forward_query numeric,
|
|
archive_expiry integer,
|
|
archive_rotation text,
|
|
max_attempts integer NOT NULL,
|
|
PRIMARY KEY (id),
|
|
CONSTRAINT fk_webhooks_targets
|
|
FOREIGN KEY (webhook_id) REFERENCES webhooks (id),
|
|
CONSTRAINT chk_targets_max_attempts CHECK (max_attempts >= 1)
|
|
);
|
|
|
|
CREATE INDEX idx_targets_deleted_at ON targets (deleted_at);
|