CREATE TABLE IF NOT EXISTS tiles_cache (
    key TEXT NOT NULL,
    value BYTEA NOT NULL,
    expires_at TIMESTAMPTZ -- NULL = no expiry
);
DO $$ BEGIN IF NOT EXISTS (
    SELECT 1
    FROM pg_constraint
    WHERE conname = 'tiles_cache_pkey'
        AND conrelid = 'public.tiles_cache'::regclass
) THEN
ALTER TABLE public.tiles_cache
ADD CONSTRAINT tiles_cache_pkey PRIMARY KEY (key);
END IF;
END $$;

CREATE INDEX IF NOT EXISTS tiles_cache_key_idx ON public.tiles_cache (key);