drop table if exists fw_core.db_run_status;

drop table if exists fw_core.Test_file_sheet_format_master;

CREATE TABLE fw_core.test_file_sheet_format_master (
	syspk serial NOT NULL,    		-- PK
	client_id int4 NOT NULL,	 	-- UKA1
	function_id int4 NOT NULL,		-- UKA2
	test_type text NOT NULL,		-- UKA3
	test_name text NOT NULL,		-- UKA4
	file_mnemonic text NOT NULL,		-- UKA5
	sheet_name text NOT NULL,		
	sheet_format text NOT NULL,
	file_sheet_mnemonic text NOT NULL,	-- UKA6
	sheet_format_mnemonic text NULL,
	stg2_function text NULL,
	trx_function text NULL,
	Created_By TEXT NULL DEFAULT current_user,
	Updated_by text NULL,
	Create_timestamp TIMESTAMP NULL DEFAULT now(),
	update_timestamp TIMESTAMP NULL
);


CREATE TABLE fw_core.db_run_status 
    (     syspk bigserial NOT NULL,
        client_id int,
        function_id int,
        user_id     int,
        user_name      text,
        file_syspk int,
        file_mnemonic text,
        file_sheet_mnemonic text,
        block_name text,
        staging_type text,
        error_function text,
        error_state    text,
            error_message     text,
            error_detail  text,
            error_hint  text,
        error_context text,
        status text,
            error_timestamp  timestamp default now(),
        CONSTRAINT mmt_DB_error_pkey PRIMARY KEY (syspk)
    );



drop table if exists  fw_core.check_table_stg_trx_count;
create table fw_core.check_table_stg_trx_count
(
schema_name text,
table_name text,
row_count int,
create_time timestamp DEFAULT CURRENT_TIMESTAMP

);

drop table if exists fw_core.check_mnemonic_count;
create table fw_core.check_mnemonic_count
(
table_name text,
syspks text,
file_mnemonic text,
file_sheet_mnemonic text,
row_count int,
create_time timestamp DEFAULT current_timestamp
);


DROP TABLE if exists fw_core.check_model_count;
CREATE TABLE fw_core.check_model_count(
	table_name text NULL,
	syspks text NULL,
	file_mnemonic text NULL,
	file_sheet_mnemonic text NULL,
	tractor_name text NULL,
	row_count int4 NULL,
	create_timestamp timestamp DEFAULT CURRENT_TIMESTAMP
);
