-- Add jetstream cursor table for tracking event processing position
CREATE TABLE IF NOT EXISTS jetstream_cursor (
    id TEXT PRIMARY KEY DEFAULT 'default',
    time_us BIGINT NOT NULL,
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- Index for tracking cursor freshness
CREATE INDEX idx_jetstream_cursor_updated_at ON jetstream_cursor(updated_at);

-- Insert default cursor starting at 0 (will be updated when events are processed)
INSERT INTO jetstream_cursor (id, time_us) VALUES ('default', 0)
ON CONFLICT (id) DO NOTHING;