CREATE TABLE IF NOT EXISTS databus_api_definition (
    id BIGINT PRIMARY KEY,
    api_code VARCHAR(255) NOT NULL,
    http_method VARCHAR(16),
    version VARCHAR(64),
    status INT,
    description VARCHAR(1024),
    rate_limit_id BIGINT,
    audit_policy_id BIGINT,
    response_template CLOB,
    updated_at TIMESTAMP,
    tenant_id BIGINT,
    create_time TIMESTAMP,
    update_time TIMESTAMP,
    creator VARCHAR(64),
    updater VARCHAR(64),
    deleted BOOLEAN
);

CREATE TABLE IF NOT EXISTS databus_api_step (
    id BIGINT PRIMARY KEY,
    api_id BIGINT NOT NULL,
    step_order INT,
    parallel_group VARCHAR(64),
    type VARCHAR(64),
    target_endpoint VARCHAR(512),
    request_mapping_expr VARCHAR(1024),
    response_mapping_expr VARCHAR(1024),
    transform_id BIGINT,
    timeout BIGINT,
    fallback_strategy VARCHAR(255),
    condition_expr VARCHAR(1024),
    stop_on_error BOOLEAN,
    tenant_id BIGINT,
    create_time TIMESTAMP,
    update_time TIMESTAMP,
    creator VARCHAR(64),
    updater VARCHAR(64),
    deleted BOOLEAN
);

CREATE TABLE IF NOT EXISTS databus_api_transform (
    id BIGINT PRIMARY KEY,
    api_id BIGINT,
    step_id BIGINT,
    phase VARCHAR(64),
    expression_type VARCHAR(64),
    expression VARCHAR(1024),
    description VARCHAR(1024),
    tenant_id BIGINT,
    create_time TIMESTAMP,
    update_time TIMESTAMP,
    creator VARCHAR(64),
    updater VARCHAR(64),
    deleted BOOLEAN
);

CREATE TABLE IF NOT EXISTS databus_policy_rate_limit (
    id BIGINT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    type VARCHAR(64),
    config CLOB,
    description VARCHAR(512),
    tenant_id BIGINT,
    create_time TIMESTAMP,
    update_time TIMESTAMP,
    creator VARCHAR(64),
    updater VARCHAR(64),
    deleted BOOLEAN
);

CREATE TABLE IF NOT EXISTS databus_policy_audit (
    id BIGINT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    type VARCHAR(64),
    config CLOB,
    description VARCHAR(512),
    tenant_id BIGINT,
    create_time TIMESTAMP,
    update_time TIMESTAMP,
    creator VARCHAR(64),
    updater VARCHAR(64),
    deleted BOOLEAN
);

CREATE TABLE IF NOT EXISTS databus_api_flow_publish (
    id BIGINT PRIMARY KEY,
    api_id BIGINT,
    version VARCHAR(64),
    status INT,
    publish_time TIMESTAMP,
    rollback_time TIMESTAMP,
    tenant_id BIGINT,
    create_time TIMESTAMP,
    update_time TIMESTAMP,
    creator VARCHAR(64),
    updater VARCHAR(64),
    deleted BOOLEAN
);

CREATE TABLE IF NOT EXISTS databus_api_definition_credential (
    id BIGINT PRIMARY KEY,
    api_id BIGINT,
    credential_id BIGINT,
    app_id VARCHAR(255),
    tenant_id BIGINT,
    create_time TIMESTAMP,
    update_time TIMESTAMP,
    creator VARCHAR(64),
    updater VARCHAR(64),
    deleted BOOLEAN
);
