-- V8: Location history - GPS user dicatat setiap interval
CREATE TABLE IF NOT EXISTS location_history (
    id         BIGSERIAL        PRIMARY KEY,
    user_id    BIGINT           NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    lat        DOUBLE PRECISION NOT NULL,
    lng        DOUBLE PRECISION NOT NULL,
    accuracy   DOUBLE PRECISION,
    speed      DOUBLE PRECISION,
    heading    DOUBLE PRECISION,
    created_at TIMESTAMP        NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_location_user_id    ON location_history(user_id);
CREATE INDEX IF NOT EXISTS idx_location_created_at ON location_history(created_at DESC);
