-- =============================================================================
-- 创建用户待办操作表
-- 用于后台配置指定用户登录后需要执行的特定操作
-- 完全可选，不影响现有任何功能
-- =============================================================================

-- 创建 user_pending_actions 表
CREATE TABLE IF NOT EXISTS "user_pending_actions" (
    "id" BIGSERIAL NOT NULL,
    "user_id" BIGINT NOT NULL,
    "action_code" VARCHAR(50) NOT NULL,
    "action_params" JSONB,
    "status" VARCHAR(20) NOT NULL DEFAULT 'PENDING',
    "priority" INTEGER NOT NULL DEFAULT 0,
    "expires_at" TIMESTAMP(3),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "completed_at" TIMESTAMP(3),
    "created_by" VARCHAR(50),

    CONSTRAINT "user_pending_actions_pkey" PRIMARY KEY ("id")
);

-- 创建索引
CREATE INDEX IF NOT EXISTS "idx_user_pending_action" ON "user_pending_actions"("user_id", "status");
CREATE INDEX IF NOT EXISTS "idx_action_code" ON "user_pending_actions"("action_code");
CREATE INDEX IF NOT EXISTS "idx_pending_action_status" ON "user_pending_actions"("status");
