-- +mixmaker Up
CREATE TABLE community_settings (
    singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),
    discord_invite_url text NOT NULL DEFAULT '',
    updated_at timestamptz NOT NULL DEFAULT now(),
    updated_by text REFERENCES accounts(id)
);

INSERT INTO community_settings(singleton) VALUES (true)
ON CONFLICT(singleton) DO NOTHING;

CREATE INDEX IF NOT EXISTS series_event_id_idx
    ON series ((body->>'eventId'));
CREATE INDEX IF NOT EXISTS events_completed_starts_at_idx
    ON events (starts_at DESC) WHERE state = 'Completed';

-- +mixmaker Down
DROP INDEX IF EXISTS events_completed_starts_at_idx;
DROP INDEX IF EXISTS series_event_id_idx;
DROP TABLE IF EXISTS community_settings;
