-- DROP SCHEMA public;

CREATE SCHEMA public AUTHORIZATION pg_database_owner;

COMMENT ON SCHEMA public IS 'standard public schema';

-- DROP SEQUENCE public.auth_group_id_seq;

CREATE SEQUENCE public.auth_group_id_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 2147483647
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE public.auth_group_permissions_id_seq;

CREATE SEQUENCE public.auth_group_permissions_id_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE public.auth_permission_id_seq;

CREATE SEQUENCE public.auth_permission_id_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 2147483647
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE public.auth_user_groups_id_seq;

CREATE SEQUENCE public.auth_user_groups_id_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE public.auth_user_id_seq;

CREATE SEQUENCE public.auth_user_id_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 2147483647
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE public.auth_user_user_permissions_id_seq;

CREATE SEQUENCE public.auth_user_user_permissions_id_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE public.django_admin_log_id_seq;

CREATE SEQUENCE public.django_admin_log_id_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 2147483647
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE public.django_content_type_id_seq;

CREATE SEQUENCE public.django_content_type_id_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 2147483647
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE public.django_migrations_id_seq;

CREATE SEQUENCE public.django_migrations_id_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;-- public.ai_algorithm 定义

-- Drop table

-- DROP TABLE public.ai_algorithm;

CREATE TABLE public.ai_algorithm (
	id varchar(40) NOT NULL,
	algorithm_code varchar(20) NOT NULL,
	algorithm_name varchar(200) NOT NULL,
	algorithm_class varchar(40) NOT NULL,
	description varchar(2000) NULL,
	scenario varchar(2000) NULL,
	algorithm_type varchar(2) NULL,
	labels text NULL,
	algorithm_status varchar(2) NULL,
	development_unit varchar(200) NULL,
	image text NULL,
	creator varchar(20) NOT NULL,
	create_time timestamptz NOT NULL,
	link_model varchar(2000) NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	algorithm_engine varchar(40) NULL,
	CONSTRAINT ai_algorithm_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_algorithm_id_12ebb08a_like ON public.ai_algorithm USING btree (id varchar_pattern_ops);


-- public.ai_algorithm_call_log 定义

-- Drop table

-- DROP TABLE public.ai_algorithm_call_log;

CREATE TABLE public.ai_algorithm_call_log (
	id varchar(40) NOT NULL,
	algorithm_id varchar(40) NOT NULL,
	algorithm_name varchar(40) NOT NULL,
	model_id varchar(40) NOT NULL,
	"Model_version" varchar(200) NOT NULL,
	input_params text NOT NULL,
	output_results text NULL,
	run_times int4 NULL,
	description varchar(2000) NULL,
	caller varchar(20) NOT NULL,
	log_time timestamptz NOT NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	evaluate_result varchar(1) NULL,
	result_desc text NULL,
	CONSTRAINT ai_algorithm_call_log_pkey PRIMARY KEY (id),
	CONSTRAINT ai_algorithm_call_log_run_times_check CHECK ((run_times >= 0))
);
CREATE INDEX ai_algorithm_call_log_id_e82865ff_like ON public.ai_algorithm_call_log USING btree (id varchar_pattern_ops);


-- public.ai_algorithm_class 定义

-- Drop table

-- DROP TABLE public.ai_algorithm_class;

CREATE TABLE public.ai_algorithm_class (
	id varchar(40) NOT NULL,
	classcode varchar(40) NOT NULL,
	classname varchar(100) NOT NULL,
	parentid varchar(40) NOT NULL,
	description varchar(1000) NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	CONSTRAINT ai_algorithm_class_classcode_key UNIQUE (classcode),
	CONSTRAINT ai_algorithm_class_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_algorithm_class_classcode_3793b613_like ON public.ai_algorithm_class USING btree (classcode varchar_pattern_ops);
CREATE INDEX ai_algorithm_class_id_0a2e4e7b_like ON public.ai_algorithm_class USING btree (id varchar_pattern_ops);


-- public.ai_algorithm_engine 定义

-- Drop table

-- DROP TABLE public.ai_algorithm_engine;

CREATE TABLE public.ai_algorithm_engine (
	id varchar(40) NOT NULL,
	enginecode varchar(40) NOT NULL,
	enginename varchar(100) NOT NULL,
	description varchar(1000) NULL,
	training_params_template text NULL,
	detect_params_template text NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	CONSTRAINT ai_algorithm_engine_enginecode_key UNIQUE (enginecode),
	CONSTRAINT ai_algorithm_engine_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_algorithm_engine_enginecode_cfe9d88d_like ON public.ai_algorithm_engine USING btree (enginecode varchar_pattern_ops);
CREATE INDEX ai_algorithm_engine_id_eba66d96_like ON public.ai_algorithm_engine USING btree (id varchar_pattern_ops);


-- public.ai_algorithm_models 定义

-- Drop table

-- DROP TABLE public.ai_algorithm_models;

CREATE TABLE public.ai_algorithm_models (
	id varchar(40) NOT NULL,
	algorithm_id varchar(40) NOT NULL,
	model_version varchar(20) NOT NULL,
	model_filepath varchar(1000) NULL,
	model_filename varchar(1000) NOT NULL,
	model_labels text NULL,
	model_createtime timestamptz NULL,
	evaluation_metrics text NULL,
	evaluation_comments text NULL,
	description varchar(2000) NULL,
	model_status varchar(2) NOT NULL,
	model_stars varchar(2) NULL,
	model_usednumber int4 NULL,
	call_duration int2 NULL,
	uploader varchar(20) NULL,
	upload_time timestamptz NOT NULL,
	is_using varchar(2) NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	CONSTRAINT ai_algorithm_models_model_usednumber_check CHECK ((model_usednumber >= 0)),
	CONSTRAINT ai_algorithm_models_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_algorithm_models_id_3079f244_like ON public.ai_algorithm_models USING btree (id varchar_pattern_ops);


-- public.ai_algorithm_output 定义

-- Drop table

-- DROP TABLE public.ai_algorithm_output;

CREATE TABLE public.ai_algorithm_output (
	id varchar(40) NOT NULL,
	algorithm_id varchar(40) NOT NULL,
	item_order int2 NOT NULL,
	item_name varchar(200) NOT NULL,
	item_desc varchar(200) NOT NULL,
	item_type varchar(2) NOT NULL,
	item_unit varchar(100) NULL,
	item_range varchar(100) NULL,
	description varchar(2000) NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	CONSTRAINT ai_algorithm_output_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_algorithm_output_id_ab741e12_like ON public.ai_algorithm_output USING btree (id varchar_pattern_ops);


-- public.ai_algorithm_params 定义

-- Drop table

-- DROP TABLE public.ai_algorithm_params;

CREATE TABLE public.ai_algorithm_params (
	id varchar(40) NOT NULL,
	algorithm_id varchar(40) NOT NULL,
	param_class varchar(2) NULL,
	param_order int2 NOT NULL,
	param_name varchar(200) NOT NULL,
	param_desc varchar(200) NOT NULL,
	param_type varchar(2) NOT NULL,
	param_unit varchar(100) NULL,
	param_range varchar(2000) NULL,
	default_values varchar(2000) NULL,
	description varchar(2000) NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	CONSTRAINT ai_algorithm_params_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_algorithm_params_id_1389b87b_like ON public.ai_algorithm_params USING btree (id varchar_pattern_ops);


-- public.ai_algorithm_train_records 定义

-- Drop table

-- DROP TABLE public.ai_algorithm_train_records;

CREATE TABLE public.ai_algorithm_train_records (
	id varchar(40) NOT NULL,
	algorithm_id varchar(40) NOT NULL,
	algorithm_name varchar(200) NOT NULL,
	train_code varchar(20) NOT NULL,
	train_title varchar(200) NOT NULL,
	train_start_time timestamptz NULL,
	link_datasets varchar(400) NULL,
	trainset_path varchar(400) NULL,
	validationset_path varchar(400) NULL,
	train_labels varchar(2000) NULL,
	train_params text NULL,
	train_total_times int4 NULL,
	model_createtime timestamptz NULL,
	model_trainresult text NULL,
	model_filename varchar(200) NULL,
	model_filepath varchar(400) NULL,
	evaluation_metrics text NULL,
	evaluation_comments text NULL,
	record_status varchar(4) NOT NULL,
	train_end_time timestamptz NULL,
	creator varchar(20) NOT NULL,
	create_time timestamptz NOT NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	train_server varchar(400) NULL,
	train_type varchar(20) NOT NULL,
	ws_server varchar(200) NULL,
	CONSTRAINT ai_algorithm_train_records_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_algorithm_train_records_id_d444e53a_like ON public.ai_algorithm_train_records USING btree (id varchar_pattern_ops);


-- public.ai_annotate_team 定义

-- Drop table

-- DROP TABLE public.ai_annotate_team;

CREATE TABLE public.ai_annotate_team (
	id varchar(40) NOT NULL,
	team_code varchar(40) NOT NULL,
	team_name varchar(200) NOT NULL,
	team_leader_id varchar(40) NULL,
	team_leader_name varchar(200) NULL,
	description varchar(2000) NULL,
	organization varchar(200) NULL,
	features varchar(200) NULL,
	status varchar(2) NOT NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	CONSTRAINT ai_annotate_team_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_annotate_team_id_9f4d943a_like ON public.ai_annotate_team USING btree (id varchar_pattern_ops);


-- public.ai_annotate_team_member 定义

-- Drop table

-- DROP TABLE public.ai_annotate_team_member;

CREATE TABLE public.ai_annotate_team_member (
	id varchar(40) NOT NULL,
	team_id varchar(40) NOT NULL,
	member_account varchar(100) NOT NULL,
	member_name varchar(40) NOT NULL,
	member_role varchar(20) NOT NULL,
	member_email varchar(200) NULL,
	remark varchar(200) NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	CONSTRAINT ai_annotate_team_member_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_annotate_team_member_id_e7dbf9c8_like ON public.ai_annotate_team_member USING btree (id varchar_pattern_ops);


-- public.ai_dataset 定义

-- Drop table

-- DROP TABLE public.ai_dataset;

CREATE TABLE public.ai_dataset (
	id varchar(40) NOT NULL,
	dataset_code varchar(40) NOT NULL, -- 数据集编号
	dataset_name varchar(200) NOT NULL, -- 数据集名称
	description varchar(2000) NULL, -- 描述
	dataset_type varchar(2) NOT NULL, -- 类型
	features varchar(200) NULL, -- 特征
	original_file_path varchar(400) NULL, -- 原始文件目录
	original_file_name varchar(8000) NULL, -- 原始文件名称
	dataset_path varchar(400) NULL, -- 数据集存储路径
	dataset_count int4 NULL, -- 样本总数
	annotated_count int4 NOT NULL DEFAULT 0, -- 已标注样本总数
	dataset_labels varchar(2000) NULL, -- 数据集标签
	status varchar(2) NOT NULL, -- 数据集状态
	creator varchar(20) NOT NULL,
	create_time timestamptz NOT NULL,
	custom1 varchar(200) NULL,
	custom3 varchar(200) NULL,
	custom2 varchar(2000) NULL,
	CONSTRAINT ai_algorithm_dataset_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_algorithm_dataset_id_2cef5ae1_like ON public.ai_dataset USING btree (id varchar_pattern_ops);

-- Column comments

COMMENT ON COLUMN public.ai_dataset.dataset_code IS '数据集编号';
COMMENT ON COLUMN public.ai_dataset.dataset_name IS '数据集名称';
COMMENT ON COLUMN public.ai_dataset.description IS '描述';
COMMENT ON COLUMN public.ai_dataset.dataset_type IS '类型';
COMMENT ON COLUMN public.ai_dataset.features IS '特征';
COMMENT ON COLUMN public.ai_dataset.original_file_path IS '原始文件目录';
COMMENT ON COLUMN public.ai_dataset.original_file_name IS '原始文件名称';
COMMENT ON COLUMN public.ai_dataset.dataset_path IS '数据集存储路径';
COMMENT ON COLUMN public.ai_dataset.dataset_count IS '样本总数';
COMMENT ON COLUMN public.ai_dataset.annotated_count IS '已标注样本总数';
COMMENT ON COLUMN public.ai_dataset.dataset_labels IS '数据集标签';
COMMENT ON COLUMN public.ai_dataset.status IS '数据集状态';


-- public.ai_dataset_sample 定义

-- Drop table

-- DROP TABLE public.ai_dataset_sample;

CREATE TABLE public.ai_dataset_sample (
	id varchar(40) NOT NULL,
	dataset_id varchar(40) NOT NULL,
	saved_path varchar(600) NOT NULL,
	original_filename varchar(200) NOT NULL,
	saved_filename varchar(200) NOT NULL,
	saved_filesize varchar(10) NOT NULL,
	rectangle varchar(2000) NULL,
	polygon text NULL,
	status varchar(2) NOT NULL,
	create_time timestamptz NOT NULL,
	custom1 varchar(200) NULL,
	custom3 varchar(200) NULL,
	custom2 varchar(1000) NULL,
	CONSTRAINT ai_dataset_sample_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_dataset_sample_id_c8268768_like ON public.ai_dataset_sample USING btree (id varchar_pattern_ops);


-- public.ai_temp_file 定义

-- Drop table

-- DROP TABLE public.ai_temp_file;

CREATE TABLE public.ai_temp_file (
	id varchar(40) NOT NULL,
	original_path varchar(600) NULL, -- 原始文件路径
	original_name varchar(200) NOT NULL, -- 原始文件名称
	original_type varchar(20) NOT NULL, -- 原始文件类型
	bucket_name varchar(200) NULL, -- minio-桶名称
	object_name varchar(200) NULL, -- 对象名称
	object_size int8 NULL, -- 对象大小
	content_type varchar(100) NULL, -- 对象类型
	status varchar(2) NOT NULL, -- 状态
	create_time timestamptz NOT NULL,
	custom1 varchar(200) NULL,
	custom3 varchar(200) NULL,
	custom2 varchar(1000) NULL,
	CONSTRAINT ai_temp_file_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_ai_temp_file_id_c8223412_like ON public.ai_temp_file USING btree (id varchar_pattern_ops);

-- Column comments

COMMENT ON COLUMN public.ai_temp_file.original_path IS '原始文件路径';
COMMENT ON COLUMN public.ai_temp_file.original_name IS '原始文件名称';
COMMENT ON COLUMN public.ai_temp_file.original_type IS '原始文件类型';
COMMENT ON COLUMN public.ai_temp_file.bucket_name IS 'minio-桶名称';
COMMENT ON COLUMN public.ai_temp_file.object_name IS '对象名称';
COMMENT ON COLUMN public.ai_temp_file.object_size IS '对象大小';
COMMENT ON COLUMN public.ai_temp_file.content_type IS '对象类型';
COMMENT ON COLUMN public.ai_temp_file.status IS '状态';


-- public.ai_annotate_task 定义

-- Drop table

-- DROP TABLE public.ai_annotate_task;

CREATE TABLE public.ai_annotate_task (
	id varchar(40) NOT NULL,
	task_name varchar(200) NOT NULL,
	annotate_type varchar(2) NOT NULL,
	description varchar(2000) NULL,
	dataset_id varchar(40) NOT NULL,
	task_count int4 NULL,
	task_range varchar(100) NULL,
	task_type varchar(2) NULL,
	region_type varchar(2) NULL,
	labels varchar(2000) NULL,
	work_type varchar(2) NOT NULL,
	task_team varchar(40) NULL,
	task_leader varchar(40) NULL,
	status varchar(2) NOT NULL,
	creator varchar(20) NOT NULL,
	create_time timestamptz NOT NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	CONSTRAINT ai_annotate_task_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_annotate_task_id_9f6b2fc0_like ON public.ai_annotate_task USING btree (id varchar_pattern_ops);

-- public.ai_annotate_task_sample 定义

-- Drop table

-- DROP TABLE public.ai_annotate_task_sample;

CREATE TABLE public.ai_annotate_task_sample (
	id varchar(40) NOT NULL,
	task_id varchar(40) NOT NULL,
	executor varchar(100) NOT NULL,
	sample_id varchar(40) NOT NULL,
	sample_path varchar(600) NOT NULL,
	sample_name varchar(200) NOT NULL,
	hard varchar(2) NOT NULL,
	annotation_content text NULL,
	class_label varchar(200) NULL,
	annotation_time timestamptz NULL,
	status varchar(2) NOT NULL,
	auditor varchar(20) NULL,
	feedback varchar(400) NULL,
	custom1 varchar(200) NULL,
	custom2 varchar(200) NULL,
	custom3 varchar(200) NULL,
	CONSTRAINT ai_annotate_task_sample_pkey PRIMARY KEY (id)
);
CREATE INDEX ai_annotate_task_sample_id_3e6e0205_like ON public.ai_annotate_task_sample USING btree (id varchar_pattern_ops);

-- ============================================================
-- 智能终端数据表 (ai_smart_terminal)
-- 场景：云端孪生镜像 — 模型训练完成后发布到云端孪生设备，
--       边缘端定期检测云端版本并下载更新，实现动态模型更新。
-- 来源：Oracle SD_AIBOX_B_H（AI边缘计算盒子基本属性表）
-- 更新日期：2026-07-09
-- ============================================================

-- public.ai_smart_terminal 定义

-- Drop table
-- DROP TABLE public.ai_smart_terminal;

CREATE TABLE public.ai_smart_terminal (
    -- ======== 基本信息 ========
    id varchar(40) NOT NULL,                -- 主键ID
    stcd varchar(40) NOT NULL,              -- 终端编码（与边缘实体设备一一对应）
    stnm varchar(255) NOT NULL,             -- 终端名称
    sttp varchar(2) NOT NULL,               -- 终端分类：01=鱼类识别AI盒子 02=鸟类识别AI盒子 03=野生动物识别AI盒子 04=鱼类分拣装置
    order_index int4 NULL,                  -- 排序

    -- ======== 位置信息 ========
    lgtd numeric(10,6) NULL,                -- 经度（单位：°）
    lttd numeric(10,6) NULL,                -- 纬度（单位：°）
    elev numeric(10,6) NULL,                -- 高程（单位：m）
    rstcd varchar(64) NULL,                 -- 所属电站编码
    base_id varchar(64) NULL,               -- 所属水电基地编码
    hbrvcd varchar(64) NULL,                -- 所属水电基地流域编码
    rvcd varchar(64) NULL,                  -- 所属流域编码

    -- ======== 设备配置 ========
    aipz varchar(1000) NULL,                -- AI盒子硬件/软件配置信息
    ipaddr varchar(512) NULL,               -- 设备IP地址
    siminfo varchar(512) NULL,              -- SIM卡信息
    lxr varchar(512) NULL,                  -- 联系人及联系电话
    purpose varchar(512) NULL,              -- 用途说明

    -- ======== 监测配置 ========
    stindx varchar(1000) NULL,              -- 监测指标列表
    dtfrqcy int4 NULL,                      -- 数据采集频次（单位：min）
    mway int2 NULL,                         -- 监测方式：0=人工监测 1=自动监测 2=混合监测

    -- ======== 启用与接入状态 ========
    usfl int2 NULL,                         -- 是否启用：0=否 1=是
    dtin int2 NULL,                         -- 数据是否接入：0=未接入 1=已接入
    dtin_tm timestamptz NULL,               -- 数据首次接入时间

    -- ======== 云端孪生 — 模型发布 ========
    model_id varchar(40) NULL,              -- 已部署模型ID（关联训练产出的模型记录）
    model_version varchar(64) NULL,         -- 已部署模型版本号
    model_path varchar(600) NULL,           -- 模型文件存储路径（MinIO对象路径）
    model_publish_time timestamptz NULL,    -- 模型发布时间（发布到云端孪生设备的时间）
    model_publish_user varchar(36) NULL,    -- 模型发布人

    -- ======== 边缘端 — 同步状态 ========
    edge_model_version varchar(64) NULL,    -- 边缘端当前运行的模型版本
    edge_update_time timestamptz NULL,      -- 边缘端最后一次模型更新时间
    last_heartbeat_time timestamptz NULL,   -- 边缘端最后心跳时间
    online_status int2 NULL,                -- 在线状态：0=离线 1=在线
    sync_check_interval int4 NULL,          -- 同步检测间隔（单位：min，边缘端轮询云端孪生设备版本的时间间隔）

    -- ======== 运维记录 ========
    remark varchar(512) NULL,               -- 备注
    record_user varchar(36) NULL,           -- 创建人
    record_time timestamptz NOT NULL DEFAULT now(), -- 创建时间
    is_deleted int2 NOT NULL DEFAULT 0,     -- 是否已删除：0=未删除 1=已删除

    CONSTRAINT ai_smart_terminal_pkey PRIMARY KEY (id)
);

CREATE INDEX ai_smart_terminal_id_idx ON public.ai_smart_terminal USING btree (id varchar_pattern_ops);
CREATE INDEX ai_smart_terminal_stcd_idx ON public.ai_smart_terminal USING btree (stcd);

-- Column comments

COMMENT ON TABLE public.ai_smart_terminal IS '智能终端数据表（云端孪生镜像）';
COMMENT ON COLUMN public.ai_smart_terminal.id IS '主键ID';
COMMENT ON COLUMN public.ai_smart_terminal.stcd IS '终端编码（与边缘实体设备一一对应）';
COMMENT ON COLUMN public.ai_smart_terminal.stnm IS '终端名称';
COMMENT ON COLUMN public.ai_smart_terminal.sttp IS '终端分类：01=鱼类识别AI盒子 02=鸟类识别AI盒子 03=野生动物识别AI盒子 04=鱼类分拣装置';
COMMENT ON COLUMN public.ai_smart_terminal.order_index IS '排序';
COMMENT ON COLUMN public.ai_smart_terminal.lgtd IS '经度（单位：°）';
COMMENT ON COLUMN public.ai_smart_terminal.lttd IS '纬度（单位：°）';
COMMENT ON COLUMN public.ai_smart_terminal.elev IS '高程（单位：m）';
COMMENT ON COLUMN public.ai_smart_terminal.rstcd IS '所属电站编码';
COMMENT ON COLUMN public.ai_smart_terminal.base_id IS '所属水电基地编码';
COMMENT ON COLUMN public.ai_smart_terminal.hbrvcd IS '所属水电基地流域编码';
COMMENT ON COLUMN public.ai_smart_terminal.rvcd IS '所属流域编码';
COMMENT ON COLUMN public.ai_smart_terminal.aipz IS 'AI盒子硬件/软件配置信息';
COMMENT ON COLUMN public.ai_smart_terminal.ipaddr IS '设备IP地址';
COMMENT ON COLUMN public.ai_smart_terminal.siminfo IS 'SIM卡信息';
COMMENT ON COLUMN public.ai_smart_terminal.lxr IS '联系人及联系电话';
COMMENT ON COLUMN public.ai_smart_terminal.purpose IS '用途说明';
COMMENT ON COLUMN public.ai_smart_terminal.stindx IS '监测指标列表';
COMMENT ON COLUMN public.ai_smart_terminal.dtfrqcy IS '数据采集频次（单位：min）';
COMMENT ON COLUMN public.ai_smart_terminal.mway IS '监测方式：0=人工监测 1=自动监测 2=混合监测';
COMMENT ON COLUMN public.ai_smart_terminal.usfl IS '是否启用：0=否 1=是';
COMMENT ON COLUMN public.ai_smart_terminal.dtin IS '数据是否接入：0=未接入 1=已接入';
COMMENT ON COLUMN public.ai_smart_terminal.dtin_tm IS '数据首次接入时间';
COMMENT ON COLUMN public.ai_smart_terminal.model_id IS '已部署模型ID（关联训练产出的模型记录）';
COMMENT ON COLUMN public.ai_smart_terminal.model_version IS '已部署模型版本号';
COMMENT ON COLUMN public.ai_smart_terminal.model_path IS '模型文件存储路径（MinIO对象路径）';
COMMENT ON COLUMN public.ai_smart_terminal.model_publish_time IS '模型发布时间（发布到云端孪生设备的时间）';
COMMENT ON COLUMN public.ai_smart_terminal.model_publish_user IS '模型发布人';
COMMENT ON COLUMN public.ai_smart_terminal.edge_model_version IS '边缘端当前运行的模型版本';
COMMENT ON COLUMN public.ai_smart_terminal.edge_update_time IS '边缘端最后一次模型更新时间';
COMMENT ON COLUMN public.ai_smart_terminal.last_heartbeat_time IS '边缘端最后心跳时间';
COMMENT ON COLUMN public.ai_smart_terminal.online_status IS '在线状态：0=离线 1=在线';
COMMENT ON COLUMN public.ai_smart_terminal.sync_check_interval IS '同步检测间隔（单位：min，边缘端轮询云端孪生设备版本的时间间隔）';
COMMENT ON COLUMN public.ai_smart_terminal.remark IS '备注';
COMMENT ON COLUMN public.ai_smart_terminal.record_user IS '创建人';
COMMENT ON COLUMN public.ai_smart_terminal.record_time IS '创建时间';
COMMENT ON COLUMN public.ai_smart_terminal.is_deleted IS '是否已删除：0=未删除 1=已删除';


-- public.auth_group 定义

-- Drop table

-- DROP TABLE public.auth_group;

CREATE TABLE public.auth_group (
	id int4 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"name" varchar(150) NOT NULL,
	CONSTRAINT auth_group_name_key UNIQUE (name),
	CONSTRAINT auth_group_pkey PRIMARY KEY (id)
);
CREATE INDEX auth_group_name_a6ea08ec_like ON public.auth_group USING btree (name varchar_pattern_ops);


-- public.auth_organization 定义

-- Drop table

-- DROP TABLE public.auth_organization;

CREATE TABLE public.auth_organization (
	id varchar(40) NOT NULL,
	orgtype varchar(2) NOT NULL,
	orgcode varchar(20) NOT NULL,
	orgname varchar(100) NOT NULL,
	parentid varchar(40) NULL,
	isvalid varchar(2) NOT NULL,
	description varchar(1000) NULL,
	custom1 varchar(100) NULL,
	custom2 varchar(100) NULL,
	custom3 varchar(100) NULL,
	CONSTRAINT auth_organization_pkey PRIMARY KEY (id)
);
CREATE INDEX auth_organization_id_c7e641af_like ON public.auth_organization USING btree (id varchar_pattern_ops);


-- public.auth_user 定义

-- Drop table

-- DROP TABLE public.auth_user;

CREATE TABLE public.auth_user (
	id int4 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"password" varchar(128) NOT NULL,
	last_login timestamptz NULL,
	is_superuser bool NOT NULL,
	username varchar(150) NOT NULL,
	first_name varchar(150) NOT NULL,
	last_name varchar(150) NOT NULL,
	email varchar(254) NOT NULL,
	is_staff bool NOT NULL,
	is_active bool NOT NULL,
	date_joined timestamptz NOT NULL,
	organization_id varchar(50) NULL,
	CONSTRAINT auth_user_pkey PRIMARY KEY (id),
	CONSTRAINT auth_user_username_key UNIQUE (username)
);
CREATE INDEX auth_user_username_6821ab7c_like ON public.auth_user USING btree (username varchar_pattern_ops);


-- public.django_content_type 定义

-- Drop table

-- DROP TABLE public.django_content_type;

CREATE TABLE public.django_content_type (
	id int4 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL,
	app_label varchar(100) NOT NULL,
	model varchar(100) NOT NULL,
	CONSTRAINT django_content_type_app_label_model_76bd3d3b_uniq UNIQUE (app_label, model),
	CONSTRAINT django_content_type_pkey PRIMARY KEY (id)
);


-- public.django_migrations 定义

-- Drop table

-- DROP TABLE public.django_migrations;

CREATE TABLE public.django_migrations (
	id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	app varchar(255) NOT NULL,
	"name" varchar(255) NOT NULL,
	applied timestamptz NOT NULL,
	CONSTRAINT django_migrations_pkey PRIMARY KEY (id)
);


-- public.django_session 定义

-- Drop table

-- DROP TABLE public.django_session;

CREATE TABLE public.django_session (
	session_key varchar(40) NOT NULL,
	session_data text NOT NULL,
	expire_date timestamptz NOT NULL,
	CONSTRAINT django_session_pkey PRIMARY KEY (session_key)
);
CREATE INDEX django_session_expire_date_a5c62663 ON public.django_session USING btree (expire_date);
CREATE INDEX django_session_session_key_c0390e0f_like ON public.django_session USING btree (session_key varchar_pattern_ops);


-- public.auth_permission 定义

-- Drop table

-- DROP TABLE public.auth_permission;

CREATE TABLE public.auth_permission (
	id int4 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"name" varchar(255) NOT NULL,
	content_type_id int4 NOT NULL,
	codename varchar(100) NOT NULL,
	CONSTRAINT auth_permission_content_type_id_codename_01ab375a_uniq UNIQUE (content_type_id, codename),
	CONSTRAINT auth_permission_pkey PRIMARY KEY (id),
	CONSTRAINT auth_permission_content_type_id_2f476e4b_fk_django_co FOREIGN KEY (content_type_id) REFERENCES public.django_content_type(id) DEFERRABLE INITIALLY DEFERRED
);
CREATE INDEX auth_permission_content_type_id_2f476e4b ON public.auth_permission USING btree (content_type_id);


-- public.auth_user_groups 定义

-- Drop table

-- DROP TABLE public.auth_user_groups;

CREATE TABLE public.auth_user_groups (
	id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	user_id int4 NOT NULL,
	group_id int4 NOT NULL,
	CONSTRAINT auth_user_groups_pkey PRIMARY KEY (id),
	CONSTRAINT auth_user_groups_user_id_group_id_94350c0c_uniq UNIQUE (user_id, group_id),
	CONSTRAINT auth_user_groups_group_id_97559544_fk_auth_group_id FOREIGN KEY (group_id) REFERENCES public.auth_group(id) DEFERRABLE INITIALLY DEFERRED,
	CONSTRAINT auth_user_groups_user_id_6a12ed8b_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES public.auth_user(id) DEFERRABLE INITIALLY DEFERRED
);
CREATE INDEX auth_user_groups_group_id_97559544 ON public.auth_user_groups USING btree (group_id);
CREATE INDEX auth_user_groups_user_id_6a12ed8b ON public.auth_user_groups USING btree (user_id);


-- public.auth_user_user_permissions 定义

-- Drop table

-- DROP TABLE public.auth_user_user_permissions;

CREATE TABLE public.auth_user_user_permissions (
	id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	user_id int4 NOT NULL,
	permission_id int4 NOT NULL,
	CONSTRAINT auth_user_user_permissions_pkey PRIMARY KEY (id),
	CONSTRAINT auth_user_user_permissions_user_id_permission_id_14a6b632_uniq UNIQUE (user_id, permission_id),
	CONSTRAINT auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm FOREIGN KEY (permission_id) REFERENCES public.auth_permission(id) DEFERRABLE INITIALLY DEFERRED,
	CONSTRAINT auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES public.auth_user(id) DEFERRABLE INITIALLY DEFERRED
);
CREATE INDEX auth_user_user_permissions_permission_id_1fbb5f2c ON public.auth_user_user_permissions USING btree (permission_id);
CREATE INDEX auth_user_user_permissions_user_id_a95ead1b ON public.auth_user_user_permissions USING btree (user_id);


-- public.django_admin_log 定义

-- Drop table

-- DROP TABLE public.django_admin_log;

CREATE TABLE public.django_admin_log (
	id int4 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL,
	action_time timestamptz NOT NULL,
	object_id text NULL,
	object_repr varchar(200) NOT NULL,
	action_flag int2 NOT NULL,
	change_message text NOT NULL,
	content_type_id int4 NULL,
	user_id int4 NOT NULL,
	CONSTRAINT django_admin_log_action_flag_check CHECK ((action_flag >= 0)),
	CONSTRAINT django_admin_log_pkey PRIMARY KEY (id),
	CONSTRAINT django_admin_log_content_type_id_c4bce8eb_fk_django_co FOREIGN KEY (content_type_id) REFERENCES public.django_content_type(id) DEFERRABLE INITIALLY DEFERRED,
	CONSTRAINT django_admin_log_user_id_c564eba6_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES public.auth_user(id) DEFERRABLE INITIALLY DEFERRED
);
CREATE INDEX django_admin_log_content_type_id_c4bce8eb ON public.django_admin_log USING btree (content_type_id);
CREATE INDEX django_admin_log_user_id_c564eba6 ON public.django_admin_log USING btree (user_id);


-- public.auth_group_permissions 定义

-- Drop table

-- DROP TABLE public.auth_group_permissions;

CREATE TABLE public.auth_group_permissions (
	id int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	group_id int4 NOT NULL,
	permission_id int4 NOT NULL,
	CONSTRAINT auth_group_permissions_group_id_permission_id_0cd325b0_uniq UNIQUE (group_id, permission_id),
	CONSTRAINT auth_group_permissions_pkey PRIMARY KEY (id),
	CONSTRAINT auth_group_permissio_permission_id_84c5c92e_fk_auth_perm FOREIGN KEY (permission_id) REFERENCES public.auth_permission(id) DEFERRABLE INITIALLY DEFERRED,
	CONSTRAINT auth_group_permissions_group_id_b120cbf9_fk_auth_group_id FOREIGN KEY (group_id) REFERENCES public.auth_group(id) DEFERRABLE INITIALLY DEFERRED
);
CREATE INDEX auth_group_permissions_group_id_b120cbf9 ON public.auth_group_permissions USING btree (group_id);
CREATE INDEX auth_group_permissions_permission_id_84c5c92e ON public.auth_group_permissions USING btree (permission_id);
