-- yudao 基座表 PostgreSQL DDL(system/infra/member),仅供本地/dev 起全栈 muse-server 用。
-- 来源:由各模块 src/test/resources/sql/create_tables.sql(H2 方言)忠实翻译为 PostgreSQL(2026-06-14)。
-- 说明:这些是【测试级】基座 schema(49 张表:system 33 / infra 10 / member 6),已实测可在 PG17 干净建库;
--       与 Muse 业务 schema(sql/muse 的 Flyway V1-V21)互不重叠。运行全栈 app 时:先建本基座表,再让
--       app 的 Flyway(baseline-on-migrate=true)补 Muse V1-V21,最后灌 yudao-base-seed-postgres.sql。
-- 限制:测试 schema 可能不含生产运行期全部列/表;正式部署应以真实 yudao postgres dump 为准。
-- 背景:本仓原只有 H2 测试 schema、无 postgres 基座 dump;这是补缺产物。详见进度总账 + 阶段7 RPC 适配 chip。

CREATE TABLE IF NOT EXISTS "system_dept" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(30) NOT NULL DEFAULT '',
    "parent_id" bigint NOT NULL DEFAULT '0',
    "sort" int NOT NULL DEFAULT '0',
    "leader_user_id" bigint DEFAULT NULL,
    "phone" varchar(11) DEFAULT NULL,
    "email" varchar(50) DEFAULT NULL,
    "status" smallint NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_dict_data" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "sort" int NOT NULL DEFAULT '0',
    "label" varchar(100) NOT NULL DEFAULT '',
    "value" varchar(100) NOT NULL DEFAULT '',
    "dict_type" varchar(100) NOT NULL DEFAULT '',
    "status" smallint NOT NULL DEFAULT '0',
    "color_type" varchar(100) NOT NULL DEFAULT '',
    "css_class" varchar(100) NOT NULL DEFAULT '',
    "remark" varchar(500) DEFAULT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_role" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(30) NOT NULL,
    "code" varchar(100) NOT NULL,
    "sort" int NOT NULL,
    "data_scope" smallint NOT NULL DEFAULT '1',
    "data_scope_dept_ids" varchar(500) NOT NULL DEFAULT '',
    "status" smallint NOT NULL,
    "type" smallint NOT NULL,
    "remark" varchar(500) DEFAULT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_role_menu" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "role_id" bigint NOT NULL,
    "menu_id" bigint NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_menu" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(50) NOT NULL,
    "permission" varchar(100) NOT NULL DEFAULT '',
    "type" smallint NOT NULL,
    "sort" int NOT NULL DEFAULT '0',
    "parent_id" bigint NOT NULL DEFAULT '0',
    "path" varchar(200) DEFAULT '',
    "icon" varchar(100) DEFAULT '#',
    "component" varchar(255) DEFAULT NULL,
    "component_name" varchar(255) DEFAULT NULL,
    "status" smallint NOT NULL DEFAULT '0',
    "visible" boolean NOT NULL DEFAULT TRUE,
    "keep_alive" boolean NOT NULL DEFAULT TRUE,
    "always_show" boolean NOT NULL DEFAULT TRUE,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_user_role" (
     "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
     "user_id" bigint NOT NULL,
     "role_id" bigint NOT NULL,
     "creator" varchar(64) DEFAULT '',
     "create_time" timestamp DEFAULT NULL,
     "updater" varchar(64) DEFAULT '',
     "update_time" timestamp DEFAULT NULL,
     "deleted" boolean DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_dict_type" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(100) NOT NULL DEFAULT '',
    "type" varchar(100) NOT NULL DEFAULT '',
    "status" smallint NOT NULL DEFAULT '0',
    "remark" varchar(500) DEFAULT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    "deleted_time" timestamp NOT NULL,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_user_session" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "token" varchar(32) NOT NULL,
    "user_id" bigint DEFAULT NULL,
    "user_type" smallint NOT NULL,
    "username" varchar(50) NOT NULL DEFAULT '',
    "user_ip" varchar(50) DEFAULT NULL,
    "user_agent" varchar(512) DEFAULT NULL,
    "session_timeout" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '' ,
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_post" (
    "id"          bigint      NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "code"        varchar(64) NOT NULL,
    "name"        varchar(50) NOT NULL,
    "sort"        integer     NOT NULL,
    "status"      smallint    NOT NULL,
    "remark"      varchar(500)         DEFAULT NULL,
    "creator"     varchar(64)          DEFAULT '',
    "create_time" timestamp   NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar(64)          DEFAULT '',
    "update_time" timestamp   NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"     boolean     NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_user_post"(
    "id"          bigint    NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "user_id"     bigint             DEFAULT NULL,
    "post_id"     bigint             DEFAULT NULL,
    "creator"     varchar(64)        DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar(64)        DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"     boolean   NOT NULL DEFAULT FALSE,
    "tenant_id"   bigint    not null default '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_notice" (
	"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
	"title" varchar(50) NOT NULL,
	"content" text NOT NULL,
	"type" smallint NOT NULL,
	"status" smallint NOT NULL DEFAULT '0',
	"creator" varchar(64) DEFAULT '',
	"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	"updater" varchar(64) DEFAULT '',
	"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	"deleted" boolean NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY("id")
);

CREATE TABLE IF NOT EXISTS "system_login_log" (
    "id"          bigint       NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "log_type"    bigint       NOT NULL,
    "user_id" bigint not null default '0',
    "user_type" smallint NOT NULL,
    "trace_id"    varchar(64)  NOT NULL DEFAULT '',
    "username"    varchar(50)  NOT NULL DEFAULT '',
    "result"      smallint     NOT NULL,
    "user_ip"     varchar(50)  NOT NULL,
    "user_agent"  varchar(512) NOT NULL,
    "creator"   varchar(64)           DEFAULT '',
    "create_time" timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"   varchar(64)           DEFAULT '',
    "update_time" timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"     boolean      NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_operate_log" (
    "id"               bigint        NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "trace_id"         varchar(64)   NOT NULL DEFAULT '',
    "user_id"          bigint        NOT NULL,
    "user_type" smallint not null default '0',
    "type"           varchar(50)   NOT NULL,
    "sub_type"             varchar(50)   NOT NULL,
    "biz_id"          bigint        NOT NULL,
    "action"          varchar(2000) NOT NULL DEFAULT '',
    "extra"             varchar(512)  NOT NULL DEFAULT '',
    "request_method"   varchar(16)            DEFAULT '',
    "request_url"      varchar(255)           DEFAULT '',
    "user_ip"          varchar(50)            DEFAULT NULL,
    "user_agent"       varchar(200)           DEFAULT NULL,
    "creator"        varchar(64)            DEFAULT '',
    "create_time"      timestamp     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"        varchar(64)            DEFAULT '',
    "update_time"      timestamp     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"          boolean       NOT NULL DEFAULT FALSE,
    "tenant_id"         bigint not null default  '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_users" (
    "id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
    "username" varchar(30) not null,
    "password" varchar(100) not null default '',
    "nickname" varchar(30) not null,
    "remark" varchar(500) default null,
    "dept_id" bigint default null,
    "post_ids" varchar(255) default null,
    "email" varchar(50) default '',
    "mobile" varchar(11) default '',
    "sex" smallint default '0',
    "avatar" varchar(100) default '',
    "status" smallint not null default '0',
    "login_ip" varchar(50) default '',
    "login_date" timestamp default null,
    "creator" varchar(64) default '',
    "create_time" timestamp not null default current_timestamp,
    "updater" varchar(64) default '',
    "update_time" timestamp not null default current_timestamp,
    "deleted" boolean not null default false,
    "tenant_id" bigint not null default  '0',
    primary key ("id")
);

CREATE TABLE IF NOT EXISTS "system_sms_channel" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "signature" varchar(10) NOT NULL,
   "code" varchar(63) NOT NULL,
   "status" smallint NOT NULL,
   "remark" varchar(255) DEFAULT NULL,
   "api_key" varchar(63) NOT NULL,
   "api_secret" varchar(63) DEFAULT NULL,
   "callback_url" varchar(255) DEFAULT NULL,
   "creator" varchar(64) DEFAULT '',
   "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "updater" varchar(64) DEFAULT '',
   "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "deleted" boolean NOT NULL DEFAULT FALSE,
   PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_sms_template" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "type" smallint NOT NULL,
    "status" smallint NOT NULL,
    "code" varchar(63) NOT NULL,
    "name" varchar(63) NOT NULL,
    "content" varchar(255) NOT NULL,
    "params" varchar(255) NOT NULL,
    "remark" varchar(255) DEFAULT NULL,
    "api_template_id" varchar(63) NOT NULL,
    "channel_id" bigint NOT NULL,
    "channel_code" varchar(63) NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_sms_log" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "channel_id" bigint NOT NULL,
   "channel_code" varchar(63) NOT NULL,
   "template_id" bigint NOT NULL,
   "template_code" varchar(63) NOT NULL,
   "template_type" smallint NOT NULL,
   "template_content" varchar(255) NOT NULL,
   "template_params" varchar(255) NOT NULL,
   "api_template_id" varchar(63) NOT NULL,
   "mobile" varchar(11) NOT NULL,
   "user_id" bigint DEFAULT '0',
   "user_type" smallint DEFAULT '0',
   "send_status" smallint NOT NULL DEFAULT '0',
   "send_time" timestamp DEFAULT NULL,
   "send_code" int DEFAULT NULL,
   "send_msg" varchar(255) DEFAULT NULL,
   "api_send_code" varchar(63) DEFAULT NULL,
   "api_send_msg" varchar(255) DEFAULT NULL,
   "api_request_id" varchar(255) DEFAULT NULL,
   "api_serial_no" varchar(255) DEFAULT NULL,
   "receive_status" smallint NOT NULL DEFAULT '0',
   "receive_time" timestamp DEFAULT NULL,
   "api_receive_code" varchar(63) DEFAULT NULL,
   "api_receive_msg" varchar(255) DEFAULT NULL,
   "creator" varchar(64) DEFAULT '',
   "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "updater" varchar(64) DEFAULT '',
   "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "deleted" boolean NOT NULL DEFAULT FALSE,
   PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_sms_code" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "mobile" varchar(11) NOT NULL,
    "code" varchar(11) NOT NULL,
    "scene" bigint NOT NULL,
    "create_ip" varchar NOT NULL,
    "today_index" int NOT NULL,
    "used" boolean NOT NULL DEFAULT FALSE,
    "used_time" timestamp DEFAULT NULL,
    "used_ip" varchar NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_social_client" (
  "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  "name" varchar(255) NOT NULL,
  "social_type" int NOT NULL,
  "user_type" int NOT NULL,
  "client_id" varchar(255) NOT NULL,
  "client_secret" varchar(255) NOT NULL,
  "public_key" varchar(2048) NOT NULL,
  "agent_id" varchar(255) NOT NULL,
  "status" int NOT NULL,
  "creator" varchar(64) DEFAULT '',
  "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updater" varchar(64) DEFAULT '',
  "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "deleted" boolean NOT NULL DEFAULT FALSE,
  "tenant_id" bigint not null default  '0',
  PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_social_user" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "type" smallint NOT NULL,
   "openid" varchar(64) NOT NULL,
   "token" varchar(256) DEFAULT NULL,
   "raw_token_info" varchar(1024) NOT NULL,
   "nickname" varchar(32) NOT NULL,
   "avatar" varchar(255) DEFAULT NULL,
   "raw_user_info" varchar(1024) NOT NULL,
   "code" varchar(64) NOT NULL,
   "state" varchar(64),
   "creator" varchar(64) DEFAULT '',
   "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "updater" varchar(64) DEFAULT '',
   "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "deleted" boolean NOT NULL DEFAULT FALSE,
   PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_social_user_bind" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "user_id" bigint NOT NULL,
   "user_type" smallint NOT NULL,
   "social_type" smallint NOT NULL,
   "social_user_id" numeric NOT NULL,
   "creator" varchar(64) DEFAULT '',
   "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "updater" varchar(64) DEFAULT '',
   "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "deleted" boolean NOT NULL DEFAULT FALSE,
   PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_tenant" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(63) NOT NULL,
    "contact_user_id" bigint NOT NULL DEFAULT '0',
    "contact_name" varchar(255) NOT NULL,
    "contact_mobile" varchar(255),
    "status" smallint NOT NULL,
    "websites" varchar(1024) DEFAULT '',
    "package_id"  bigint NOT NULL,
    "expire_time" timestamp NOT NULL,
    "account_count" int NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_tenant_package" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(30) NOT NULL,
    "status" smallint NOT NULL,
    "remark" varchar(256),
    "menu_ids" varchar(2048) NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_oauth2_client" (
  "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  "client_id" varchar NOT NULL,
  "secret" varchar NOT NULL,
  "name" varchar NOT NULL,
  "logo" varchar NOT NULL,
  "description" varchar,
  "status" int NOT NULL,
  "access_token_validity_seconds" int NOT NULL,
  "refresh_token_validity_seconds" int NOT NULL,
  "redirect_uris" varchar NOT NULL,
  "authorized_grant_types" varchar NOT NULL,
  "scopes" varchar NOT NULL DEFAULT '',
  "auto_approve_scopes" varchar NOT NULL DEFAULT '',
  "authorities" varchar NOT NULL DEFAULT '',
  "resource_ids" varchar NOT NULL DEFAULT '',
  "additional_information" varchar NOT NULL DEFAULT '',
  "creator" varchar DEFAULT '',
  "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updater" varchar DEFAULT '',
  "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "deleted" boolean NOT NULL DEFAULT FALSE,
  PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_oauth2_approve" (
  "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  "user_id" bigint NOT NULL,
  "user_type" smallint NOT NULL,
  "client_id" varchar NOT NULL,
  "scope" varchar NOT NULL,
  "approved" boolean NOT NULL DEFAULT FALSE,
  "expires_time" timestamp NOT NULL,
  "creator" varchar DEFAULT '',
  "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updater" varchar DEFAULT '',
  "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "deleted" boolean NOT NULL DEFAULT FALSE,
  PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_oauth2_access_token" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "user_id" bigint NOT NULL,
   "user_type" smallint NOT NULL,
   "user_info" varchar NOT NULL,
   "access_token" varchar NOT NULL,
   "refresh_token" varchar NOT NULL,
   "client_id" varchar NOT NULL,
   "scopes" varchar NOT NULL,
   "approved" boolean NOT NULL DEFAULT FALSE,
   "expires_time" timestamp NOT NULL,
   "creator" varchar DEFAULT '',
   "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "updater" varchar DEFAULT '',
   "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "deleted" boolean NOT NULL DEFAULT FALSE,
   "tenant_id" bigint not null,
   PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_oauth2_refresh_token" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "user_id" bigint NOT NULL,
    "user_type" smallint NOT NULL,
    "refresh_token" varchar NOT NULL,
    "client_id" varchar NOT NULL,
    "scopes" varchar NOT NULL,
    "approved" boolean NOT NULL DEFAULT FALSE,
    "expires_time" timestamp NOT NULL,
    "creator" varchar DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_oauth2_code" (
     "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
     "user_id" bigint NOT NULL,
     "user_type" smallint NOT NULL,
     "code" varchar NOT NULL,
     "client_id" varchar NOT NULL,
     "scopes" varchar NOT NULL,
     "expires_time" timestamp NOT NULL,
     "redirect_uri" varchar NOT NULL,
     "state" varchar NOT NULL,
     "creator" varchar DEFAULT '',
     "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
     "updater" varchar DEFAULT '',
     "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
     "deleted" boolean NOT NULL DEFAULT FALSE,
     PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_mail_account" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "mail" varchar NOT NULL,
    "username" varchar NOT NULL,
    "password" varchar NOT NULL,
    "host" varchar NOT NULL,
    "port" int NOT NULL,
    "ssl_enable" boolean NOT NULL,
    "starttls_enable" boolean NOT NULL,
    "creator" varchar DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_mail_template" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar NOT NULL,
    "code" varchar NOT NULL,
    "account_id" bigint NOT NULL,
    "nickname" varchar,
    "title" varchar NOT NULL,
    "content" varchar NOT NULL,
    "params" varchar NOT NULL,
    "status" varchar NOT NULL,
    "remark" varchar,
    "creator" varchar DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_mail_log" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "user_id" bigint,
    "user_type" varchar,
    "to_mails" varchar NOT NULL,
    "cc_mails" varchar,
    "bcc_mails" varchar,
    "account_id" bigint NOT NULL,
    "from_mail" varchar NOT NULL,
    "template_id" bigint NOT NULL,
    "template_code" varchar NOT NULL,
    "template_nickname" varchar,
    "template_title" varchar NOT NULL,
    "template_content" varchar NOT NULL,
    "template_params" varchar NOT NULL,
    "send_status" varchar NOT NULL,
    "send_time" timestamp,
    "send_message_id" varchar,
    "send_exception" varchar,
    "creator" varchar DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_notify_template" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar NOT NULL,
    "code" varchar NOT NULL,
    "nickname" varchar NOT NULL,
    "content" varchar NOT NULL,
    "type" varchar NOT NULL,
    "params" varchar,
    "status" varchar NOT NULL,
    "remark" varchar,
    "creator" varchar DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "system_notify_message" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "user_id" bigint NOT NULL,
    "user_type" varchar NOT NULL,
    "template_id" bigint NOT NULL,
    "template_code" varchar NOT NULL,
    "template_nickname" varchar NOT NULL,
    "template_content" varchar NOT NULL,
    "template_type" int NOT NULL,
    "template_params" varchar NOT NULL,
    "read_status" boolean NOT NULL,
    "read_time" varchar,
    "creator" varchar DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "infra_config" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "category" varchar(50) NOT NULL,
    "type" smallint NOT NULL,
    "name" varchar(100) NOT NULL DEFAULT '',
    "config_key" varchar(100) NOT NULL DEFAULT '',
    "value" varchar(500) NOT NULL DEFAULT '',
    "visible" boolean NOT NULL,
    "remark" varchar(500) DEFAULT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "infra_file_config" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(63) NOT NULL,
    "storage" smallint NOT NULL,
    "remark" varchar(255),
    "master" boolean NOT NULL,
    "config" varchar(4096) NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "infra_file" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "config_id" bigint NOT NULL,
    "name" varchar(256),
    "path" varchar(512),
    "url" varchar(1024),
    "type" varchar(63) DEFAULT NULL,
    "size" bigint NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    "tenant_id" bigint not null default  '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "infra_job" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(32) NOT NULL,
    "status" smallint NOT NULL,
    "handler_name" varchar(64) NOT NULL,
    "handler_param" varchar(255) DEFAULT NULL,
    "cron_expression" varchar(32) NOT NULL,
    "retry_count" int NOT NULL DEFAULT '0',
    "retry_interval" int NOT NULL DEFAULT '0',
    "monitor_timeout" int NOT NULL DEFAULT '0',
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "infra_job_log" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "job_id" bigint NOT NULL,
    "handler_name" varchar(64) NOT NULL,
    "handler_param" varchar(255) DEFAULT NULL,
    "execute_index" smallint NOT NULL DEFAULT '1',
    "begin_time" timestamp NOT NULL,
    "end_time" timestamp DEFAULT NULL,
    "duration" int DEFAULT NULL,
    "status" smallint NOT NULL,
    "result" varchar(4000) DEFAULT '',
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "infra_api_access_log" (
    "id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
    "trace_id" varchar(64) not null default '',
    "user_id" bigint not null default '0',
    "user_type" smallint not null default '0',
    "application_name" varchar(50) not null,
    "request_method" varchar(16) not null default '',
    "request_url" varchar(255) not null default '',
    "request_params" varchar(8000) not null default '',
    "response_body" varchar(8000) not null default '',
    "user_ip" varchar(50) not null,
    "user_agent" varchar(512) not null,
    "operate_module"           varchar(50)   NOT NULL,
    "operate_name"             varchar(50)   NOT NULL,
    "operate_type"     bigint     NOT NULL DEFAULT '0',
    "begin_time" timestamp not null,
    "end_time" timestamp not null,
    "duration" integer not null,
    "result_code" integer not null default '0',
    "result_msg" varchar(512) default '',
    "creator" varchar(64) default '',
    "create_time" timestamp not null default current_timestamp,
    "updater" varchar(64) default '',
    "update_time" timestamp not null default current_timestamp,
    "deleted" boolean not null default false,
    "tenant_id" bigint not null default  '0',
    primary key ("id")
);

-- 补:InfraApiErrorLogDO 走 @KeySequence("infra_api_error_log_seq") 取主键;原翻译用 IDENTITY 无此序列,致 500 时错误日志写入再抛 relation 不存在(2026-06-14)
CREATE SEQUENCE IF NOT EXISTS infra_api_error_log_seq;
CREATE TABLE IF NOT EXISTS "infra_api_error_log" (
    "id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
    "trace_id" varchar(64) not null,
    "user_id" bigint not null default '0',
    "user_type" smallint not null default '0',
    "application_name" varchar(50) not null,
    "request_method" varchar(16) not null,
    "request_url" varchar(255) not null,
    "request_params" varchar(8000) not null,
    "user_ip" varchar(50) not null,
    "user_agent" varchar(512) not null,
    "exception_time" timestamp not null,
    "exception_name" varchar(128) not null default '',
    "exception_message" text not null,
    "exception_root_cause_message" text not null,
    "exception_stack_trace" text not null,
    "exception_class_name" varchar(512) not null,
    "exception_file_name" varchar(512) not null,
    "exception_method_name" varchar(512) not null,
    "exception_line_number" integer not null,
    "process_status" smallint not null,
    "process_time" timestamp default null,
    "process_user_id" bigint default '0',
    "creator" varchar(64) default '',
    "create_time" timestamp not null default current_timestamp,
    "updater" varchar(64) default '',
    "update_time" timestamp not null default current_timestamp,
    "deleted" boolean not null default false,
    "tenant_id" bigint not null default  '0',
    primary key ("id")
);

CREATE TABLE IF NOT EXISTS "infra_data_source_config" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name" varchar(100) NOT NULL,
    "url" varchar(1024) NOT NULL,
    "username" varchar(255) NOT NULL,
    "password" varchar(255) NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "infra_codegen_table" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "data_source_config_id" bigint not null,
    "scene" smallint not null DEFAULT 1,
    "table_name" varchar(200) NOT NULL,
    "table_comment" varchar(500) NOT NULL,
    "remark" varchar(500) NOT NULL,
    "module_name" varchar(30) NOT NULL,
    "business_name" varchar(30) NOT NULL,
    "class_name" varchar(100) NOT NULL,
    "class_comment" varchar(50) NOT NULL,
    "author" varchar(50) NOT NULL,
    "template_type" smallint not null DEFAULT 1,
    "front_type" smallint not null,
    "parent_menu_id" bigint not null,
    "master_table_id" bigint not null,
    "sub_join_column_id" bigint not null,
    "sub_join_many" boolean not null,
    "tree_parent_column_id" bigint not null,
    "tree_name_column_id" bigint not null,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "infra_codegen_column" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "table_id" bigint not null,
    "column_name" varchar(200) NOT NULL,
    "data_type" varchar(100) NOT NULL,
    "column_comment" varchar(500) NOT NULL,
    "nullable" smallint not null,
    "primary_key" smallint not null,
    "ordinal_position" int not null,
    "java_type" varchar(32) NOT NULL,
    "java_field" varchar(64) NOT NULL,
    "dict_type" varchar(200) NOT NULL,
    "example" varchar(64) NOT NULL,
    "create_operation" boolean not null,
    "update_operation" boolean not null,
    "list_operation" boolean not null,
    "list_operation_condition" varchar(32) not null,
    "list_operation_result" boolean not null,
    "html_type" varchar(32) NOT NULL,
    "creator" varchar(64) DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "member_user"
(
    "id"          bigint       NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "nickname"    varchar(30)  NOT NULL DEFAULT '',
    "name"        varchar(30)  NULL,
    sex           smallint     null,
    birthday      timestamp    null,
    area_id       int          null,
    mark          varchar(255) null,
    point         int                   default 0 null,
    "avatar"      varchar(255) NOT NULL DEFAULT '',
    "status"      smallint     NOT NULL,
    "mobile"      varchar(11)  NOT NULL,
    "password"    varchar(100) NOT NULL DEFAULT '',
    "register_ip" varchar(32)  NOT NULL,
    -- 补:MemberUserDO.registerTerminal(注册终端枚举);原翻译遗漏致 account/profile 等读 member_user 报 column 不存在(2026-06-14)
    "register_terminal" int     NULL,
    "login_ip"    varchar(50)  NULL     DEFAULT '',
    "login_date"  timestamp    NULL     DEFAULT NULL,
    "tag_ids"     varchar(255) NULL     DEFAULT NULL,
    "level_id"    bigint       NULL     DEFAULT NULL,
    "experience"  bigint       NULL     DEFAULT NULL,
    "group_id"    bigint       NULL     DEFAULT NULL,
    "creator"     varchar(64)  NULL     DEFAULT '',
    "create_time" timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar(64)  NULL     DEFAULT '',
    "update_time" timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"     boolean      NOT NULL DEFAULT '0',
    "tenant_id"   bigint       not null default '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "member_address" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "user_id" bigint NOT NULL,
    "name" varchar(10) NOT NULL,
    "mobile" varchar(20) NOT NULL,
    "area_id" bigint NOT NULL,
    "detail_address" varchar(250) NOT NULL,
    "default_status" boolean NOT NULL,
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "creator" varchar(64) DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted" boolean NOT NULL DEFAULT FALSE,
    "updater" varchar(64) DEFAULT '',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "member_tag"
(
    "id"          bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name"        varchar  NOT NULL,
    "creator"     varchar           DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar           DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"     boolean  NOT NULL DEFAULT FALSE,
    "tenant_id"   bigint   NOT NULL default '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "member_level"
(
    "id"             bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name"           varchar  NOT NULL,
    "experience"     int      NOT NULL,
    "level"          int      NOT NULL,
    "discount_percent"       int      NOT NULL,
    "icon"           varchar  NOT NULL,
    "background_url" varchar  NOT NULL,
    "creator"        varchar           DEFAULT '',
    "create_time"    timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"        varchar           DEFAULT '',
    "update_time"    timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"        boolean  NOT NULL DEFAULT FALSE,
    "tenant_id"      bigint   not null default '0',
    "status" smallint NOT NULL DEFAULT '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "member_group"
(
    "id"          bigint   NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "name"        varchar  NOT NULL,
    "remark"      varchar  NOT NULL,
    "status" smallint NOT NULL DEFAULT '0',
    "creator"     varchar           DEFAULT '',
    "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"     varchar           DEFAULT '',
    "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"     boolean  NOT NULL DEFAULT FALSE,
    "tenant_id"      bigint   not null default '0',
    PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "member_brokerage_record"
(
    "id"            int      NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "user_id"       bigint   NOT NULL,
    "biz_id"        varchar  NOT NULL,
    "biz_type"      varchar  NOT NULL,
    "title"         varchar  NOT NULL,
    "price"         int      NOT NULL,
    "total_price"   int      NOT NULL,
    "description"   varchar  NOT NULL,
    "status"        varchar  NOT NULL,
    "frozen_days"   int      NOT NULL,
    "unfreeze_time" varchar,
    "creator"       varchar           DEFAULT '',
    "create_time"   timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updater"       varchar           DEFAULT '',
    "update_time"   timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted"       boolean  NOT NULL DEFAULT FALSE,
    "tenant_id"      bigint   not null default '0',
    PRIMARY KEY ("id")
);
