Delimiter //
/**
 * Author:  armen
 * Created: 30 janv. 2018
 */
Drop Procedure if exists LOADER_CREATE_TABLE_MEMBERSACCRED_REFDATA//
Create Procedure LOADER_CREATE_TABLE_MEMBERSACCRED_REFDATA ()
Begin
    Drop Table If Exists LOADER_MEMBERSACCRED_REFDATA;
    
    Create Table LOADER_MEMBERSACCRED_REFDATA (
        ID_LOADER_MEMBERSACCRED_REFDATA Int Unsigned Not Null Auto_increment
        -- champs pour le traitements de l'import
        , LOADER_STATUS_ID_LOADER_STATUS Int Unsigned Not Null
        , LOADER_MEMBERSACCRED_ID_LOADER_MEMBERSACCRED Int Unsigned Not Null
        

        , ENTITIES_REF_SEQUENCE smallint Unsigned Null -- numéro de la sequence fourni par le fichier
        , ENTITIES_REF_DATA_CODE varchar(20) -- valeur de la référence, fourni par le fichier

        , ENTITIES_REF_ID_ENTITIES_REF Int Unsigned -- id reference, issu normalisation
        , ID_ENTITIES_REF_DATAS Int Unsigned -- issu normalisation si code trouvé
        , NEW_ID_ENTITIES_REF_DATAS Int Unsigned -- issu normalisation si code non trouvé

		, LOADER_REFDATA_TYPE Varchar(25) Not NULL Default 'ACCRED_ACCOUNTS'

        -- contraintes et indexes
        , Primary Key (ID_LOADER_MEMBERSACCRED_REFDATA)
        , Index (LOADER_STATUS_ID_LOADER_STATUS)
        , Index (LOADER_MEMBERSACCRED_ID_LOADER_MEMBERSACCRED)
        , Index (LOADER_REFDATA_TYPE, ENTITIES_REF_SEQUENCE)
        , Index (ENTITIES_REF_ID_ENTITIES_REF, ENTITIES_REF_DATA_CODE)

    ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
End //
Delimiter ;
call LOADER_CREATE_TABLE_MEMBERSACCRED_REFDATA();
