CREATE TABLE "DATABUS_API_ACCESS_LOG"
(
    "ID" BIGINT NOT NULL,
    "TRACE_ID" VARCHAR(64) DEFAULT NULL,
    "API_CODE" VARCHAR(128) DEFAULT NULL,
    "API_VERSION" VARCHAR(32) DEFAULT NULL,
    "REQUEST_METHOD" VARCHAR(16) DEFAULT NULL,
    "REQUEST_PATH" VARCHAR(512) DEFAULT NULL,
    "REQUEST_QUERY" TEXT,
    "REQUEST_HEADERS" TEXT,
    "REQUEST_BODY" TEXT,
    "RESPONSE_STATUS" INT DEFAULT NULL,
    "RESPONSE_MESSAGE" VARCHAR(500) DEFAULT NULL,
    "RESPONSE_BODY" TEXT,
    "STATUS" SMALLINT DEFAULT 3 NOT NULL,
    "ERROR_CODE" VARCHAR(100) DEFAULT NULL,
    "ERROR_MESSAGE" VARCHAR(1000) DEFAULT NULL,
    "EXCEPTION_STACK" TEXT,
    "CLIENT_IP" VARCHAR(64) DEFAULT NULL,
    "USER_AGENT" VARCHAR(512) DEFAULT NULL,
    "DURATION" BIGINT DEFAULT NULL,
    "REQUEST_TIME" DATETIME(6) DEFAULT CURRENT_TIMESTAMP NOT NULL,
    "RESPONSE_TIME" DATETIME(6) DEFAULT NULL,
    "STEP_RESULTS" TEXT,
    "EXTRA" TEXT,
    "CREATOR" VARCHAR(64) DEFAULT NULL,
    "CREATE_TIME" DATETIME(6) DEFAULT CURRENT_TIMESTAMP NOT NULL,
    "UPDATER" VARCHAR(64) DEFAULT NULL,
    "UPDATE_TIME" DATETIME(6) DEFAULT CURRENT_TIMESTAMP NOT NULL,
    "DELETED" BIT DEFAULT '0' NOT NULL,
    "TENANT_ID" BIGINT DEFAULT 0 NOT NULL,
    NOT CLUSTER PRIMARY KEY("ID")) STORAGE(ON "MAIN", CLUSTERBTR) ;

COMMENT ON TABLE DATABUS_API_ACCESS_LOG IS 'Databus API 访问日志表';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."API_CODE" IS 'API 编码';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."API_VERSION" IS 'API 版本';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."CLIENT_IP" IS '客户端 IP';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."CREATE_TIME" IS '创建时间';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."CREATOR" IS '创建者';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."DELETED" IS '是否删除';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."DURATION" IS '请求耗时（毫秒）';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."ERROR_CODE" IS '业务错误码';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."ERROR_MESSAGE" IS '错误信息';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."EXCEPTION_STACK" IS '异常堆栈';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."EXTRA" IS '额外调试信息（JSON 字符串）';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."ID" IS '日志主键';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."REQUEST_BODY" IS '请求体（JSON 字符串）';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."REQUEST_HEADERS" IS '请求头（JSON 字符串）';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."REQUEST_METHOD" IS '请求方法';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."REQUEST_PATH" IS '请求路径';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."REQUEST_QUERY" IS '请求查询参数（JSON 字符串）';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."REQUEST_TIME" IS '请求时间';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."RESPONSE_BODY" IS '响应体（JSON 字符串）';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."RESPONSE_MESSAGE" IS '响应提示信息';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."RESPONSE_STATUS" IS '响应 HTTP 状态码';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."RESPONSE_TIME" IS '响应时间';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."STATUS" IS '访问状态：0-成功 1-客户端错误 2-服务端错误 3-未知';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."STEP_RESULTS" IS '执行步骤结果（JSON 字符串）';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."TENANT_ID" IS '租户编号';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."TRACE_ID" IS '追踪 ID';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."UPDATER" IS '更新者';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."UPDATE_TIME" IS '更新时间';
COMMENT ON COLUMN DATABUS_API_ACCESS_LOG."USER_AGENT" IS 'User-Agent';


CREATE OR REPLACE  INDEX "IDX_DATABUS_API_ACCESS_LOG_TRACE" ON "DATABUS_API_ACCESS_LOG"("TRACE_ID" ASC) STORAGE(ON "MAIN", CLUSTERBTR) ;
CREATE OR REPLACE  INDEX "IDX_DATABUS_API_ACCESS_LOG_CODE" ON "DATABUS_API_ACCESS_LOG"("API_CODE" ASC) STORAGE(ON "MAIN", CLUSTERBTR) ;
CREATE OR REPLACE  INDEX "IDX_DATABUS_API_ACCESS_LOG_METHOD" ON "DATABUS_API_ACCESS_LOG"("REQUEST_METHOD" ASC) STORAGE(ON "MAIN", CLUSTERBTR) ;
CREATE OR REPLACE  INDEX "IDX_DATABUS_API_ACCESS_LOG_STATUS" ON "DATABUS_API_ACCESS_LOG"("STATUS" ASC) STORAGE(ON "MAIN", CLUSTERBTR) ;
CREATE OR REPLACE  INDEX "IDX_DATABUS_API_ACCESS_LOG_RESP_STATUS" ON "DATABUS_API_ACCESS_LOG"("RESPONSE_STATUS" ASC) STORAGE(ON "MAIN", CLUSTERBTR) ;
CREATE OR REPLACE  INDEX "IDX_DATABUS_API_ACCESS_LOG_REQUEST_TIME" ON "DATABUS_API_ACCESS_LOG"("REQUEST_TIME" ASC) STORAGE(ON "MAIN", CLUSTERBTR) ;
CREATE OR REPLACE  INDEX "IDX_DATABUS_API_ACCESS_LOG_CLIENT_IP" ON "DATABUS_API_ACCESS_LOG"("CLIENT_IP" ASC) STORAGE(ON "MAIN", CLUSTERBTR) ;
CREATE OR REPLACE  INDEX "IDX_DATABUS_API_ACCESS_LOG_TENANT" ON "DATABUS_API_ACCESS_LOG"("TENANT_ID" ASC) STORAGE(ON "MAIN", CLUSTERBTR) ;

