Files
llmgw/internal/store/migrations/postgres/0024_batches.sql
T

57 lines
2.1 KiB
SQL

-- Ported from the SQLite migration of the same number.
-- The Files and Batch APIs. A file is what a client uploaded (a batch's
-- requests) or what a batch wrote (its answers, its errors), owned by the
-- project of the key that made it. A batch is a file of requests served one
-- by one at the lowest priority; each finished line is kept as it is
-- served, so a batch survives the control plane restarting under it, and
-- the lease says which gateway is working on it.
CREATE TABLE files (
id TEXT PRIMARY KEY,
owner TEXT NOT NULL,
purpose TEXT NOT NULL,
filename TEXT NOT NULL,
bytes BIGINT NOT NULL,
content BYTEA NOT NULL,
created_at BIGINT NOT NULL,
expires_at BIGINT NOT NULL DEFAULT 0
);
CREATE INDEX files_owner ON files (owner, created_at);
CREATE TABLE batches (
id TEXT PRIMARY KEY,
owner TEXT NOT NULL,
key_id TEXT NOT NULL,
endpoint TEXT NOT NULL,
input_file_id TEXT NOT NULL,
completion_window TEXT NOT NULL,
status TEXT NOT NULL,
output_file_id TEXT NOT NULL DEFAULT '',
error_file_id TEXT NOT NULL DEFAULT '',
total BIGINT NOT NULL DEFAULT 0,
completed BIGINT NOT NULL DEFAULT 0,
failed BIGINT NOT NULL DEFAULT 0,
created_at BIGINT NOT NULL,
in_progress_at BIGINT NOT NULL DEFAULT 0,
finalizing_at BIGINT NOT NULL DEFAULT 0,
completed_at BIGINT NOT NULL DEFAULT 0,
failed_at BIGINT NOT NULL DEFAULT 0,
expired_at BIGINT NOT NULL DEFAULT 0,
cancelling_at BIGINT NOT NULL DEFAULT 0,
cancelled_at BIGINT NOT NULL DEFAULT 0,
expires_at BIGINT NOT NULL,
metadata TEXT NOT NULL DEFAULT '',
errors TEXT NOT NULL DEFAULT '',
lease_owner TEXT NOT NULL DEFAULT '',
lease_until BIGINT NOT NULL DEFAULT 0
);
CREATE INDEX batches_owner ON batches (owner, created_at);
CREATE INDEX batches_status ON batches (status, lease_until);
CREATE TABLE batch_results (
batch_id TEXT NOT NULL,
line BIGINT NOT NULL,
ok BIGINT NOT NULL,
data TEXT NOT NULL,
PRIMARY KEY (batch_id, line)
);