-- Durable SOAP PropertyCollector views / page tokens / WaitForUpdates versions.

CREATE TABLE vsphere_pc_state (
    kind text NOT NULL CHECK (kind IN ('view', 'token', 'version', 'meta')),
    key text NOT NULL,
    payload jsonb NOT NULL DEFAULT '{}'::jsonb,
    updated_at timestamptz NOT NULL DEFAULT now(),
    PRIMARY KEY (kind, key)
);

CREATE INDEX vsphere_pc_state_kind_idx ON vsphere_pc_state (kind);

-- Ephemeral console tickets issued by REST/SOAP.
CREATE TABLE vsphere_console_tickets (
    ticket text PRIMARY KEY,
    vm_moid text NOT NULL REFERENCES vsphere_objects (moid) ON DELETE CASCADE,
    payload jsonb NOT NULL DEFAULT '{}'::jsonb,
    created_at timestamptz NOT NULL DEFAULT now()
);
