SET search_path TO kcg, public;

-- 지진 이벤트 (USGS)
CREATE TABLE IF NOT EXISTS seismic_events (
    id BIGSERIAL PRIMARY KEY,
    usgs_id VARCHAR(30) UNIQUE NOT NULL,
    magnitude DOUBLE PRECISION NOT NULL,
    depth DOUBLE PRECISION,
    lat DOUBLE PRECISION NOT NULL,
    lng DOUBLE PRECISION NOT NULL,
    place VARCHAR(255),
    event_time TIMESTAMPTZ NOT NULL,
    collected_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_seismic_events_time ON seismic_events(event_time DESC);

-- 기압 데이터 (Open-Meteo)
CREATE TABLE IF NOT EXISTS pressure_readings (
    id BIGSERIAL PRIMARY KEY,
    station VARCHAR(50) NOT NULL,
    lat DOUBLE PRECISION NOT NULL,
    lng DOUBLE PRECISION NOT NULL,
    pressure_hpa DOUBLE PRECISION NOT NULL,
    reading_time TIMESTAMPTZ NOT NULL,
    collected_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    UNIQUE(station, reading_time)
);

CREATE INDEX IF NOT EXISTS idx_pressure_readings_time ON pressure_readings(reading_time DESC);
