drop table if exists trx.trx;

CREATE TABLE trx.trx (
	syspk serial NOT NULL,
	client_id int4 NOT NULL,
	function_id int4 NOT NULL,
	test_file_mnemonic text NULL,
	test_file_sheet_mnemonic text NULL,
	test_file_id int4 NULL,
	test_file_name text NULL,
	test_instance_id int4 NULL,
	tractor_make text NULL,
	tractor_model text NULL,
	tractor_engine_hp int4 NULL,
	wheel_drive_type text NULL,
	"configuration" text NULL,
	test_instance_tractor_id int4 NULL,
	season text NULL,
	test_date date NULL,
	test_date_year int4 NULL,
	test_date_quarter int4 NULL,
	test_date_month int4 NULL,
	test_date_dayofmonth int2 NULL,
	test_date_dayofweek int2 NULL,
	test_mode text NULL,
	test_type text NULL,
	test_sub_type text NULL,
	test_condition text NULL,
	test_purpose text NULL,
	test_iteration_number int4 NULL,
	test_ambient text NULL,
	test_tractor_yn text null,
	mahindra_model_yn text null,
	location_name text NULL,
	name_of_implement text NULL,
	type_of_implement text NULL,
	implement_weight_kg int4 NULL,
	tyre_size text NULL,
	tyre_ply_rating int4 NULL,
	tyre_pressure_kg_per_cm2 numeric NULL,
	engine_speed_var int4 NULL,
	engine_load_pct_var int4 NULL,
	gear_used text NULL,
	gear_used_up_slope_1 text NULL,
	gear_used_up_slope_2 text NULL,
	gear_used_down_slope text NULL,
	gear_forward_reverse text NULL,
	gear_pedal_effort_parameters text NULL,
	sensor_body_location text NULL,
	effort_type text NULL,
	engine_rpm_type text NULL,
	fuel_consumption_lit_per_hr numeric NULL,
	fuel_consumption_lit_per_acr numeric NULL,
	area_covered_acr_per_hr numeric NULL,
	speed_kmph numeric NULL,
	wheel_slippage_pct numeric NULL,
	field_efficiency_pct numeric NULL,
	productivity numeric NULL,
	erpmdrop_straight_1stpass_low int4 NULL,
	erpmdrop_straight_1stpass_high int4 NULL,
	erpmdrop_straight_2ndpass_low int4 NULL,
	erpmdrop_straight_2ndpass_high int4 NULL,
	erpmdrop_straight_3rdpass_low int4 NULL,
	erpmdrop_straight_3rdpass_high int4 NULL,
	erpmdrop_turn_1stpass_low int4 NULL,
	erpmdrop_turn_1stpass_high int4 NULL,
	erpmdrop_turn_2ndpass_low int4 NULL,
	erpmdrop_turn_2ndpass_high int4 NULL,
	erpmdrop_turn_3rdpass_low int4 NULL,
	erpmdrop_turn_3rdpass_high int4 NULL,
	no_of_passes int4 NULL,
	depth_of_cut_cm_low numeric NULL,
	depth_of_cut_cm_high numeric NULL,
	total_dist_travelled_km numeric NULL,
	mileage_kmpl numeric NULL,
	power_kw numeric NULL,
	pull_kgf numeric NULL,
	pull_KN numeric NULL,
	effort_kg numeric NULL,
	power_hp numeric NULL,
	torque_kg_m numeric NULL,
	torque_Nm numeric NULL,
	sfc_g_per_kwh numeric NULL,
	sfc_gms_per_hp_hr numeric NULL,
	fuelling_mm3_per_stroke_per_cyl numeric NULL,
	specific_energy_kWh_per_ltr numeric NULL,
	temp_engine_oil_c int4 NULL,
	temp_engine_oil_high_c int4 NULL,
	temp_trans_oil_c int4 NULL,
	temp_trans_oil_high_c int4 NULL,
	temp_coolant_c int4 NULL,
	temp_coolant_high_c int4 NULL,
	temp_fuel_in_c int4 NULL,
	temp_fuel_high_c int4 NULL,
	temp_fuel_out_c int4 NULL,
	temp_water_outlet_c int4 NULL,
	temp_exhaust_c int4 NULL,
	temp_fuel_temp_c int4 NULL,
	pct_of_backup_torque int4 NULL,
	equ_cblock_row_number_torque_nm numeric NULL,
	max_equ_crankshaft_torque_nm numeric NULL,
	load_pct int4 NULL,
	load_kg numeric NULL,
	required_stopping_distance_m numeric NULL,
	actual_stopping_distance_m numeric NULL,
	decceleartoin_m_per_s2 numeric NULL,
	lifting_time_sec int4 NULL,
	lowering_time_sec int4 NULL,
	speed_on_high_rpm_kmph numeric NULL,
	speed_on_low_rpm_kmph numeric NULL,
	speed_on_rated_rpm_kmph numeric NULL,
	body_location_temperature int4 NULL,
	speed_pto_rpm int4 NULL,
	brake_pedal_travel_lh_in_mm int4 NULL,
	brake_pedal_travel_rh_in_mm int4 NULL,
	brake_pedal_travel_latched_in_mm int4 NULL,
	pedal_travel_in_mm int4 null,
	noise_dba numeric NULL,
	test_file_load_date timestamp NULL,
	updated_by text NULL DEFAULT CURRENT_USER,
	created_by text NULL DEFAULT CURRENT_USER,
	update_timestamp timestamp NULL,
	create_timestamp timestamp NULL DEFAULT now(),
	CONSTRAINT fw_ads_pkey PRIMARY KEY (syspk)
);

DROP TABLE  if exists trx.trx_detailed;
CREATE TABLE trx.trx_detailed (
	syspk serial NOT NULL,
	client_id int4 NOT NULL,
	function_id int4 NOT NULL,
	test_file_mnemonic text NULL,
	test_file_sheet_mnemonic text NULL,
	test_file_id int4 NULL,
	test_file_name text NULL,
	test_instance_id int4 NULL,
	tractor_make text NULL,
	tractor_model text NULL,
	tractor_engine_hp int4 NULL,
	wheel_drive_type text NULL,
	"configuration" text NULL,
	test_insance_tractor_id int4 NULL,
	season text NULL,
	test_date date NULL,
	test_date_year int4 NULL,
	test_date_quarter int4 NULL,
	test_date_month int4 NULL,
	test_date_dayofmonth int2 NULL,
	test_date_dayofweek int2 NULL,
	test_mode text NULL,
	test_type text NULL,
	test_sub_type text NULL,
	test_condition text NULL,
	location_name text NULL,
	test_detail_type text NULL,
	time_sec numeric NULL,
	steering_angle_degree numeric NULL,
	effort_kg numeric NULL,
	test_file_load_date timestamp NULL,
	updated_by text NULL DEFAULT CURRENT_USER,
	created_by text NULL DEFAULT CURRENT_USER,
	update_timestamp timestamp NULL DEFAULT now(),
	create_timestamp timestamp NULL DEFAULT now()
);

drop table if exists trx.trx_tractor_specifications;
create table trx.trx_tractor_specifications (
	syspk serial NOT NULL,				-- PK
	Client_Id INT NOT NULL,				
	Function_Id INT NOT NULL,			
	Test_file_name text NOT NULL,		
	Tractor_model text, 				
	Tractor_Spec_group text,			
	Tractor_spec_parameter text,		
	Tractor_spec_param_value text,
	Created_By TEXT NULL DEFAULT current_user,
	Updated_by text NULL,
	Create_timestamp TIMESTAMP NULL DEFAULT now(),
	update_timestamp TIMESTAMP NULL
);