CREATE TABLE IF NOT EXISTS qfixdpl_messages (
    id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    quote_req_id TEXT NOT NULL,
    trade_id    TEXT,
    j_message   JSONB NOT NULL,
    created_at  TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_messages_quote_req_id ON qfixdpl_messages(quote_req_id);
CREATE INDEX IF NOT EXISTS idx_messages_created_at ON qfixdpl_messages(created_at);
CREATE INDEX IF NOT EXISTS idx_messages_trade_id ON qfixdpl_messages(trade_id);

CREATE TABLE IF NOT EXISTS qfixdpl_logs (
    id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    quote_req_id TEXT NOT NULL UNIQUE,
    trade_id    TEXT,
    raw_msg     TEXT NOT NULL,
    created_at  TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at  TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_dpl_logs_trade_id ON qfixdpl_logs(trade_id);
