--set RunWizardOnStartup instead of wrong RunWizardOnStarup and delete old parameter
UPDATE CONFIGURATION
SET VALUE = (
		SELECT IFNULL(VALUE, 'True')
		FROM CONFIGURATION
		WHERE [SECTION] = 'Core'
			AND [KEY] = 'RunWizardOnStarup'
		)
WHERE [SECTION] = 'Core'
	AND [KEY] = 'RunWizardOnStartup';

DELETE
FROM CONFIGURATION
WHERE [SECTION] = 'Core'
	AND [KEY] = 'RunWizardOnStarup';
	
--set a new value for TempFilePersistence parameter
UPDATE CONFIGURATION
SET VALUE = 10
WHERE [SECTION] = 'Core'
	AND [KEY] = 'TempFilePersistence';

--change interval of notifychanged event
UPDATE SCHEDULED_EVENTS
SET MINUTE = '15,45'
WHERE EVENT = 'notifychanged';

-- create temp table GTL_ENTITY_RELATIONS
CREATE TABLE TMP_GTL_ENTITY_RELATIONS_010001 (
	IDCOMPANY VARCHAR(6) NULL
	,TPENTITY_FATHER INTEGER NULL
	,CODE_FATHER VARCHAR(20) NULL
	,TPENTITY_KEY INTEGER NULL
	,CODE_KEY VARCHAR(20) NULL
	,TPENTITY_CHILD INTEGER NULL
	,CODE_CHILD VARCHAR(20) NULL
	,PRIMARY KEY (
		IDCOMPANY
		,TPENTITY_FATHER
		,CODE_FATHER
		,TPENTITY_KEY
		,CODE_KEY
		,TPENTITY_CHILD
		,CODE_CHILD
		)
	);

-- Copying rows from original table to the new table
INSERT INTO TMP_GTL_ENTITY_RELATIONS_010001 (
	IDCOMPANY
	,TPENTITY_FATHER
	,CODE_FATHER
	,TPENTITY_CHILD
	,CODE_CHILD
	,TPENTITY_KEY
	,CODE_KEY
	)
SELECT IDCOMPANY
	,TPENTITY_FATHER
	,CODE_FATHER
	,TPENTITY_CHILD
	,CODE_CHILD
	,0 AS TPENTITY_KEY
	,'' AS CODE_KEY
FROM GTL_ENTITY_RELATIONS;

-- Droping the original table and renaming the temporary table
DROP TABLE GTL_ENTITY_RELATIONS;

ALTER TABLE TMP_GTL_ENTITY_RELATIONS_010001 RENAME TO GTL_ENTITY_RELATIONS;

-- Creating associated indexes
CREATE INDEX IF NOT EXISTS IDX_GTL_ENTITY_RELATIONS_1 ON GTL_ENTITY_RELATIONS (
	IDCOMPANY ASC
	,TPENTITY_FATHER ASC
	,CODE_FATHER ASC
	,TPENTITY_CHILD ASC
	,CODE_CHILD ASC
	);
	
-- Creating index on attirbutions
CREATE INDEX IF NOT EXISTS IDX_GTL_ENTITY_ATTRIBUTIONS_1 ON GTL_ENTITY_ATTRIBUTIONS (
	TPENTITY ASC
	,CODENTITY ASC
	);

-- Creating index on transactions
CREATE INDEX IF NOT EXISTS IDX_GTL_TRANSACTIONS_1 ON GTL_TRANSACTIONS (
	IDCOMPANY ASC
	,IDEMPLOY ASC
	,TSTRANSACTION ASC
	);