Delimiter //
/**
	procédure qui cré la table de profil global
	permet d'avoir une table avec l'intégralité des compte par membre
*/

Drop Procedure if Exists BUSINESS_COMPUTE_MEMBERS_CREDENTIALS_GLOBAL_PROFILES//
Create Procedure BUSINESS_COMPUTE_MEMBERS_CREDENTIALS_GLOBAL_PROFILES(
	In forceClear Int 
)
Begin
	memberAccCredentialGlobalProfilesInit: Begin

		Set @mbrAlltableExists = Coalesce(
								(
									Select count(*)
									From information_schema.TABLES
									Where
										TABLE_SCHEMA = schema()
										And `TABLE_NAME` = 'TMP_ACCOUNTS_CREDENTIALS_MEMBER__ALL'
								)
								, 0
							);

		if Coalesce(forceClear, 0)  > 0  Then
			-- purge de la table principale
			Drop Table If exists TMP_ACCOUNTS_CREDENTIALS_MEMBER__ALL;
			set @mbrAlltableExists = 0;
		End If;

		if @mbrAlltableExists = 0 Then
			-- la table est a recréer
			Create Table TMP_ACCOUNTS_CREDENTIALS_MEMBER__ALL (
						MEMBERS_ID_MEMBERS Int Unsigned Not Null
						, ACCOUNTS_ID_ACCOUNTS Int Unsigned Not Null
						, DF_ACC_PRFLS_ID_DF_ACC_PRFLS Int Unsigned Null
						, Primary Key (ACCOUNTS_ID_ACCOUNTS, MEMBERS_ID_MEMBERS)
						, Index ( MEMBERS_ID_MEMBERS)
						, Index ( DF_ACC_PRFLS_ID_DF_ACC_PRFLS)
					)
				;
		End if;
	End;
	memberAccCredentialGlobalDefaultTableInit: Begin

		Set @defaultMbrtableExists = Coalesce(
								(
									Select count(*)
									From information_schema.TABLES
									Where
										TABLE_SCHEMA = schema()
										And `TABLE_NAME` = 'TMP_ACCOUNTS_CREDENTIALS_MEMBER__0'
								)
								, 0
							);


		if @defaultMbrtableExists = 0 Then
			-- la table est a recréer
			call BUSINESS_COMPUTE_MEMBERS_CREDENTIALS_CREATE_PROFILE_TABLE(0
                                                                        , 1
                                                                        , null
                                                                        , @bcmcgp_tblName
                                                                    )
                    ;
		End if;
	End;



End //
Delimiter ;

