CREATE TYPE torrent_state AS ENUM ( 'pending', 'downloading', 'paused', 'finished', 'error' ); CREATE TABLE torrents ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), info_hash TEXT NOT NULL UNIQUE, name TEXT, source TEXT NOT NULL, output_path TEXT NOT NULL, total_bytes BIGINT, downloaded_bytes BIGINT NOT NULL DEFAULT 0, state torrent_state NOT NULL DEFAULT 'pending', error_message TEXT, added_at TIMESTAMPTZ NOT NULL DEFAULT now(), updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), completed_at TIMESTAMPTZ );