-- migrations/002_add_payment_orders.sql
CREATE TABLE IF NOT EXISTS payment_orders (
    id           SERIAL PRIMARY KEY,
    user_id      INTEGER NOT NULL REFERENCES users(id),
    order_no     VARCHAR(64) UNIQUE NOT NULL,
    package_type VARCHAR(20) NOT NULL,
    amount       INTEGER NOT NULL,
    status       VARCHAR(20) NOT NULL DEFAULT 'pending',
    paid_at      TIMESTAMPTZ,
    expires_at   TIMESTAMPTZ,
    created_at   TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_payment_orders_user_id ON payment_orders(user_id);
CREATE INDEX IF NOT EXISTS idx_payment_orders_order_no ON payment_orders(order_no);