-- ============================================================
--  V9: 관리자 계정(아이디/비밀번호 로그인) — 회원(users)과 분리
-- ============================================================

CREATE TABLE admin_account (
    id            BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    username      VARCHAR(50)  NOT NULL UNIQUE,
    password_hash VARCHAR(255) NOT NULL,          -- BCrypt
    name          VARCHAR(50)  NOT NULL,
    created_at    TIMESTAMPTZ  NOT NULL DEFAULT now(),
    last_login_at TIMESTAMPTZ
);

-- 관리자 세션 (회원 auth_session 과 분리)
CREATE TABLE admin_session (
    token      VARCHAR(64)  PRIMARY KEY,
    admin_id   BIGINT       NOT NULL REFERENCES admin_account(id) ON DELETE CASCADE,
    expires_at TIMESTAMPTZ  NOT NULL,
    created_at TIMESTAMPTZ  NOT NULL DEFAULT now()
);
CREATE INDEX idx_admin_session_expires ON admin_session(expires_at);
