import { rawQuery } from '../src/db.js';

async function run() {
  try {
    await rawQuery(`
      CREATE TABLE IF NOT EXISTS signals (
        id SERIAL PRIMARY KEY,
        ticker TEXT NOT NULL,
        ts TIMESTAMPTZ NOT NULL,
        lane TEXT NOT NULL,
        score NUMERIC NOT NULL,
        grade TEXT NOT NULL,
        entry_price NUMERIC NOT NULL,
        features JSONB NOT NULL,
        regime JSONB NOT NULL,
        data_age_sec INT,
        resolved BOOLEAN DEFAULT FALSE,
        intraday_move NUMERIC,
        hit_2R_first BOOLEAN,
        ret_5d NUMERIC,
        ret_10d NUMERIC,
        excess_3m NUMERIC,
        excess_6m NUMERIC,
        excess_12m NUMERIC
      );
      CREATE INDEX IF NOT EXISTS idx_signals_lane_grade ON signals(lane, grade, ts);
    `);
    console.log('Signals table initialized.');
    process.exit(0);
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
}
run();
