-- Migration: 000001_init.up.sql

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE IF NOT EXISTS encrypted_logs (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    log_type TEXT NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    encrypted_payload BYTEA NOT NULL,
    blind_index_hash TEXT,
    server_id TEXT NOT NULL,
    session_id TEXT
);

CREATE INDEX IF NOT EXISTS idx_logs_created_at ON encrypted_logs(created_at);
CREATE INDEX IF NOT EXISTS idx_logs_blind_hash ON encrypted_logs(blind_index_hash);

CREATE TABLE IF NOT EXISTS telemetry (
    timestamp TIMESTAMP WITH TIME ZONE PRIMARY KEY DEFAULT CURRENT_TIMESTAMP,
    community_id TEXT NOT NULL,
    server_fps DOUBLE PRECISION NOT NULL,
    player_count INTEGER NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_telemetry_community_id ON telemetry(community_id);
