Delimiter //
/**
 * Author:  armen
 * Created: 12 oct. 2022
 */

Drop Procedure If Exists BUSINESS_PROCESSES_PREPARE_FOR_BACKUP //
Create Procedure BUSINESS_PROCESSES_PREPARE_FOR_BACKUP(
)
Begin
    bppfb_main: Begin
        bppfb_prcss_tbls: Begin

            Drop Table If Exists TMP_BKP_PROCESSES;
            Create Table TMP_BKP_PROCESSES AS 
            select tar.* From PROCESSES as tar;
			Alter table TMP_BKP_PROCESSES
				 add column NEW_ID_PROCESSES Int Unsigned
				, add index (ID_PROCESSES)
			;

            Drop Table If Exists TMP_BKP_PROCESS_LIST;
            Create Table TMP_BKP_PROCESS_LIST AS 
            select tar.* From PROCESS_LIST as tar;
			Alter table TMP_BKP_PROCESS_LIST
				add column NEW_PRCSSLST_ID_PROCESSES Int Unsigned
				, add column NEW_PRCSSLST_ID_PROCESS_TREE_DESC Int Unsigned
				, add index (PRCSSLST_ID_PROCESSES)
				, add index (PRCSSLST_ID_PROCESS_TREE_DESC)
			;

            Drop Table If Exists TMP_BKP_PROCESS_TREE_DESC;
            Create Table TMP_BKP_PROCESS_TREE_DESC AS 
            select tar.* From PROCESS_TREE_DESC as tar;
			Alter table TMP_BKP_PROCESS_TREE_DESC
				 add column NEW_ID_PROCESS_TREE_DESC Int Unsigned
				, add index (ID_PROCESS_TREE_DESC)
			;

            Drop Table If Exists TMP_BKP_PROCESS;
            Create Table TMP_BKP_PROCESS AS 
            select tar.* From PROCESS as tar;
			Alter table TMP_BKP_PROCESS
				 add column NEW_ID_PROCESS Int Unsigned
				, add column NEW_PRCSS_EXT_ID Int Unsigned
				, add index (ID_PROCESS)
				, add index (PRCSS_EXT_ID)
			;

            Drop Table If Exists TMP_BKP_TASK_LIST_DESC;
            Create Table TMP_BKP_TASK_LIST_DESC AS 
            select tar.* From TASK_LIST_DESC as tar;
			Alter table TMP_BKP_TASK_LIST_DESC
				 add column NEW_ID_TASK_LIST_DESC Int Unsigned
				, add index (ID_TASK_LIST_DESC)
			;

            Drop Table If Exists TMP_BKP_TASK_LIST;
            Create Table TMP_BKP_TASK_LIST AS 
            select tar.* From TASK_LIST as tar;
			Alter table TMP_BKP_TASK_LIST
                  add column NEW_TSKLST_ID_DF_TASKS Int Unsigned
				, add column NEW_TSKLST_ID_DF_TASKS_PLANS Int Unsigned
				, add column NEW_TSKLST_ID_DF_ACCOUNTS_STATUS Int Unsigned
				, add index (TSKLST_ID_DF_TASKS)
				, add index (TSKLST_ID_DF_TASKS_PLANS)
				, add index (TSKLST_ID_DF_ACCOUNTS_STATUS)
			;

            Drop Table If Exists TMP_BKP_CONDITIONS;
            Create Table TMP_BKP_CONDITIONS AS 
            select tar.* From CONDITIONS as tar;
			Alter table TMP_BKP_CONDITIONS
				 add column NEW_ID_CONDITIONS Int Unsigned
				, add index (ID_CONDITIONS)
			;

            Drop Table If Exists TMP_BKP_CONDITION_TREE;
            Create Table TMP_BKP_CONDITION_TREE AS 
            select tar.* From CONDITION_TREE as tar;
			Alter table TMP_BKP_CONDITION_TREE
				 add column NEW_ID_CONDITION_TREE Int Unsigned
				, add column NEW_CNDTNTR_ID_CONDITIONS Int Unsigned
				, add index (ID_CONDITION_TREE)
				, add index (CNDTNTR_ID_CONDITIONS)
			;

            Drop Table If Exists TMP_BKP_CONDITION_NODE;
            Create Table TMP_BKP_CONDITION_NODE AS 
            select tar.* From CONDITION_NODE as tar;
			Alter table TMP_BKP_CONDITION_NODE
				 add column NEW_CNDTNND_ID_CONDITION_TREE Int Unsigned
				, add index (CNDTNND_ID_CONDITION_TREE)
			;

            Drop Table If Exists TMP_BKP_PROCESS_TREE;
            Create Table TMP_BKP_PROCESS_TREE AS 
            select tar.* From PROCESS_TREE as tar;
			Alter table TMP_BKP_PROCESS_TREE
				 add column NEW_PRCSSTR_ID_PROCESS Int Unsigned
				, add column NEW_PRCSSTR_ID_CONDITION Int Unsigned
				, add column NEW_PRCSSTR_ID_PROCESS_TREE_DESC Int Unsigned
				, add column NEW_PRCSSTR_ID_TASK_LIST_DESC Int Unsigned
				, add index (PRCSSTR_ID_PROCESS)
				, add index (PRCSSTR_ID_CONDITION)
				, add index (PRCSSTR_ID_PROCESS_TREE_DESC)
				, add index (PRCSSTR_ID_TASK_LIST_DESC)
			;

        end;

        bppfb_tasks_tbls: Begin

            Drop Table If Exists TMP_BKP_DF_TASK_FAMILIES;
            Create Table TMP_BKP_DF_TASK_FAMILIES AS 
            select tar.* From DF_TASK_FAMILIES as tar;
			Alter table TMP_BKP_DF_TASK_FAMILIES
				 add column NEW_ID_DF_TASK_FAMILIES Int Unsigned
				, add index (ID_DF_TASK_FAMILIES)
			;

            Drop Table If Exists TMP_BKP_DF_TASK_FAMILIES_LNG;
            Create Table TMP_BKP_DF_TASK_FAMILIES_LNG AS 
            select tar.* From DF_TASK_FAMILIES_LNG as tar;
			Alter table TMP_BKP_DF_TASK_FAMILIES_LNG
				 add column NEW_DF_TASK_FAM_ID_DF_TASK_FAM Int Unsigned
				, add index (DF_TASK_FAM_ID_DF_TASK_FAM)
				, add index (DF_LANGUAGES_ID_DF_LANGUAGES)
			;

            Drop Table If Exists TMP_BKP_DF_FUNCTIONS;
            Create Table TMP_BKP_DF_FUNCTIONS AS 
            select tar.* From DF_FUNCTIONS as tar;
			Alter table TMP_BKP_DF_FUNCTIONS
				 add column NEW_ID_DF_FUNCTIONS Int Unsigned
				, add index (ID_DF_FUNCTIONS)
			;


            Drop Table If Exists TMP_BKP_DF_TASKS;
            Create Table TMP_BKP_DF_TASKS AS 
            select tar.* From DF_TASKS as tar;
			Alter table TMP_BKP_DF_TASKS
				 add column NEW_ID_DF_TASKS Int Unsigned
				, add column NEW_DF_TASK_FAM_ID_DF_TASK_FAM Int Unsigned
				, add column NEW_DF_TASKS_ID_DF_TASKS_FALLBACK Int Unsigned
				, add index (ID_DF_TASKS)
				, add index (DF_TASK_FAM_ID_DF_TASK_FAM)
				, add index (DF_TASKS_ID_DF_TASKS_FALLBACK)
			;


            Drop Table If Exists TMP_BKP_DF_RECIPIENTS;
            Create Table TMP_BKP_DF_RECIPIENTS AS 
            select tar.* From DF_RECIPIENTS as tar;
			Alter table TMP_BKP_DF_RECIPIENTS
				 add column NEW_DF_TASKS_ID_DF_TASKS Int Unsigned
				, add column NEW_DF_FUNC_ID_DF_FUNC_MEMBER Int Unsigned
				, add column NEW_DF_FUNC_ID_DF_FUNC_CONTACT Int Unsigned
				, add index (DF_TASKS_ID_DF_TASKS)
				, add index (DF_FUNC_ID_DF_FUNC_MEMBER)
				, add index (DF_FUNC_ID_DF_FUNC_CONTACT)
			;



            Drop Table If Exists TMP_BKP_DF_MESSAGES_TYPES;
            Create Table TMP_BKP_DF_MESSAGES_TYPES AS 
            select tar.* From DF_MESSAGES_TYPES as tar;
			Alter table TMP_BKP_DF_MESSAGES_TYPES
				 add column NEW_ID_DF_MESSAGES_TYPES Int Unsigned
				, add index (ID_DF_MESSAGES_TYPES)
			;

            Drop Table If Exists TMP_BKP_DF_MESSAGES;
            Create Table TMP_BKP_DF_MESSAGES AS 
            select tar.* From DF_MESSAGES as tar;
			Alter table TMP_BKP_DF_MESSAGES
				 add column NEW_ID_DF_MESSAGES Int Unsigned
				, add column NEW_DF_MSG_TYPES_ID_DF_MSG_TYPES Int Unsigned
-- 				, add index (ID_DF_MESSAGES)
				, add index (DF_MSG_TYPES_ID_DF_MSG_TYPES)
				, add index (DF_LANGUAGES_ID_DF_LANGUAGES)
			;


            Drop Table If Exists TMP_BKP_DF_MODELS_TYPES;
            Create Table TMP_BKP_DF_MODELS_TYPES AS 
            select tar.* From DF_MODELS_TYPES as tar;
			Alter table TMP_BKP_DF_MODELS_TYPES
				 add column NEW_ID_DF_MODELS_TYPES Int Unsigned
				, add index (ID_DF_MODELS_TYPES)
			;

            Drop Table If Exists TMP_BKP_DF_MODELS;
            Create Table TMP_BKP_DF_MODELS AS 
            select tar.* From DF_MODELS as tar;
			Alter table TMP_BKP_DF_MODELS
				 add column NEW_ID_DF_MODELS Int Unsigned
				, add column NEW_MODELS_TYPES_ID_MODELS_TYPES Int Unsigned
				, add index (ID_DF_MODELS)
				, add index (MODELS_TYPES_ID_MODELS_TYPES)
				, add index (DF_LANG_ID_DF_LANG)
			;


            Drop Table If Exists TMP_BKP_DF_SMS_TYPES;
            Create Table TMP_BKP_DF_SMS_TYPES AS 
            select tar.* From DF_SMS_TYPES as tar;
			Alter table TMP_BKP_DF_SMS_TYPES
				 add column NEW_ID_DF_SMS_TYPES Int Unsigned
				, add index (ID_DF_SMS_TYPES)
			;

            Drop Table If Exists TMP_BKP_DF_SMS;
            Create Table TMP_BKP_DF_SMS AS 
            select tar.* From DF_SMS as tar;
			Alter table TMP_BKP_DF_SMS
				 add column NEW_ID_DF_SMS Int Unsigned
				, add column NEW_DF_SMS_TYPES_ID_DF_SMS_TYPES Int Unsigned
				, add index (ID_DF_SMS)
				, add index (DF_SMS_TYPES_ID_DF_SMS_TYPES)
				, add index (DF_LANGUAGES_ID_DF_LANGUAGES)
			;


            Drop Table If Exists TMP_BKP_DF_MEDIAS;
            Create Table TMP_BKP_DF_MEDIAS AS 
            select tar.* From DF_MEDIAS as tar;
			Alter table TMP_BKP_DF_MEDIAS
				 add column NEW_MODELS_TYPES_ID_MODELS_TYPES Int Unsigned
				, add column NEW_SMS_TYPES_ID_SMS_TYPES Int Unsigned
				, add column NEW_MSG_TYPES_ID_MSG_TYPES Int Unsigned
				, add column NEW_DF_TASKS_ID_DF_TASKS Int Unsigned
				, add index (DF_TASKS_ID_DF_TASKS)
				, add index (MODELS_TYPES_ID_MODELS_TYPES)
				, add index (SMS_TYPES_ID_SMS_TYPES)
				, add index (MSG_TYPES_ID_MSG_TYPES)
			;

            Drop Table If Exists TMP_BKP_DF_TASKS_PLANS;
            Create Table TMP_BKP_DF_TASKS_PLANS AS 
            select tar.* From DF_TASKS_PLANS as tar;
			Alter table TMP_BKP_DF_TASKS_PLANS
				 add column NEW_ID_DF_TASKS_PLANS Int Unsigned
				, add index (ID_DF_TASKS_PLANS)
			;

            Drop Table If Exists TMP_BKP_DF_TASKS_PLANS_has_DF_TASKS;
            Create Table TMP_BKP_DF_TASKS_PLANS_has_DF_TASKS AS 
            select tar.* From DF_TASKS_PLANS_has_DF_TASKS as tar;
			Alter table TMP_BKP_DF_TASKS_PLANS_has_DF_TASKS
				 add column NEW_DF_TASKS_ID_DF_TASKS Int Unsigned
				, add column NEW_DF_TKS_PLANS_ID_DF_TKS_PLANS Int Unsigned
				, add index (DF_TASKS_ID_DF_TASKS)
				, add index (DF_TKS_PLANS_ID_DF_TKS_PLANS)
			;


            Drop Table If Exists TMP_BKP_DF_ACCOUNTS_STATUS;
            Create Table TMP_BKP_DF_ACCOUNTS_STATUS AS 
            select tar.* From DF_ACCOUNTS_STATUS as tar;
			Alter table TMP_BKP_DF_ACCOUNTS_STATUS
				 add column NEW_ID_DF_ACCOUNTS_STATUS Int Unsigned
				, add index (ID_DF_ACCOUNTS_STATUS)
				, add index (DF_ACCOUNTS_STATUS_CODE)
			;

            Drop Table If Exists TMP_BKP_DF_ACCOUNTS_STATUS_LNG;
            Create Table TMP_BKP_DF_ACCOUNTS_STATUS_LNG AS 
            select tar.* From DF_ACCOUNTS_STATUS_LNG as tar;
			Alter table TMP_BKP_DF_ACCOUNTS_STATUS_LNG
				 add column NEW_DF_ACCOUNTS_STATUS_ID_DF_ACCOUNTS_STATUS Int Unsigned
				, add index (DF_ACCOUNTS_STATUS_ID_DF_ACCOUNTS_STATUS)
				, add index (DF_LANGUAGES_ID_DF_LANGUAGES)
			;

        end;
    end;

End //

Delimiter ;