/* 
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Table Name	: TInventoryData
 * Description	: BMS Inventory Data
 * createAt		: 2020.12.02
 * createBy		: JK.Woo
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */
drop table if exists TInventoryData;
--drop sequence if exists inventory_data_seq;

--create sequence inventory_data_seq start 1;

create table TInventoryData
(
	manufacture_date	integer			not null				,
	module_name			varchar(20)		null					,
	pcb_sn				varchar(20)		not null				,
	module_sn			varchar(32)		null					,
	create_date			timestamp		not null				,
	modify_date			timestamp		not null				,

    primary key (pcb_sn, module_sn)
);
create index inventory_data_idx1 on TInventoryData (pcb_sn);
create index inventory_data_idx2 on TInventoryData (module_sn);

/* 
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Table Name	: TErrorLogTable
 * Description	: Error Message Log Table
 * createAt		: 2019.11.04
 * createBy		: JK.Woo
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */
drop table if exists TErrorLogTable;
--drop sequence if exists module_group_seq;

--create sequence module_group_seq start 1;

create table TErrorLogTable
(
	create_date									timestamp		not null				,
	pcb_sn										varchar(20)		not null				,
	module_sn									varchar(20)		null					,
	PROCESS										varchar(20)		not null				,
	ERROR_TYPE									varchar(100)	not null				,
	ERROR_MSG									varchar(200)	not null
);

/* 
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Table Name	: TModuleValue
 * Description	: Battery Module Value and Status Table
 * createAt		: 2021.03.04
 * createBy		: JK.Woo
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */
drop table if exists TModuleValue;

create table TModuleValue
(
	create_date									timestamp		not null			,
	module_no									integer			not null			,
	pcb_sn										varchar(20)		null				,
	module_sn									varchar(32)		null				,
	comm_fail									BOOLEAN 		null				,
	op_status									integer 		null				,
	alarm_status								integer 		null				,
	module_voltage								float 			null				,
	module_current								float 			null				,
	module_soc									float			null				,
	module_soh									float			null				,
	cell_voltage_01								float			null				,
	cell_voltage_02								float			null				,
	cell_voltage_03								float			null				,
	cell_voltage_04								float			null				,
	cell_voltage_05								float			null				,
	cell_voltage_06								float			null				,
	cell_voltage_07								float			null				,
	cell_voltage_08								float			null				,
	cell_voltage_09								float			null				,
	cell_voltage_10								float			null				,
	cell_voltage_11								float			null				,
	cell_voltage_12								float			null				,
	cell_voltage_13								float			null				,
	cell_voltage_14								float			null				,
	cell_voltage_15								float			null				,
	cell_voltage_16								float			null				,
	cell_voltage_17								float			null				,
	cell_voltage_18								float			null				,
	cell_voltage_19								float			null				,
	cell_voltage_20								float			null				,
	cell_voltage_21								float			null				,
	cell_voltage_22								float			null				,
	cell_voltage_23								float			null				,
	cell_voltage_24								float			null				,
	cell_voltage_25								float			null				,
	cell_voltage_26								float			null				,
	cell_voltage_27								float			null				,
	cell_voltage_28								float			null				,
	cell_voltage_29								float			null				,
	cell_voltage_30								float			null				,
	cell_voltage_31								float			null				,
	cell_voltage_32								float			null				,
	cell_voltage_33								float			null				,
	cell_voltage_34								float			null				,
	cell_voltage_35								float			null				,
	cell_voltage_36								float			null				,
	temperature_01								float			null				,
	temperature_02								float			null				,
	temperature_03								float			null				,
	temperature_04								float			null				,
	temperature_05								float			null				,
	temperature_06								float			null				,
	temperature_07								float			null				,
	temperature_08								float			null				,
	temperature_09								float			null				,
	temperature_10								float			null				,
	temperature_11								float			null				,
	temperature_12								float			null				,
	temperature_13								float			null				,
	temperature_14								float			null				,
	temperature_15								float			null				,
	temperature_16								float			null				,
	warning										smallint		null				,
	fault										smallint		null				,

    primary key (module_sn)
);

create index ModuleValue_data_idx1 on TModuleValue (create_date);
