#!/bin/bash

source /usr/bin/xivo-upgrade-functions

if [ "$XIVO_VERSION_INSTALLED" \> "2023.02.00" ]; then
    exit 0
fi

display_ucaddon_upgrade_msg() {
	cat <<-EOF
	*****************************************************
	*  INFO: UC Addon db migration                      *
	*                                                   *
	*  Please refer to XiVO Solutions doc               *
	*    Release Notes > Upgrage > Jabbah to Kuma       *
	*                                                   *
	*  - pgxivocc and db_replic containers were removed *
	*    to finish the migration you MUST run:          *
	*                                                   *
	     xivo-dcomp up -d --remove-orphans
	     xivocc-dcomp up -d --remove-orphans
	*                                                   *
	*  - Call history was cleaned: xivo_stats will      *
	*    recompute it. You can check the progress with  *
	*    the following command:                         *
	*
	    psql -U asterisk -qc '
	    SELECT
	        x.max_cel_id,
	        y.last_cel_id AS last_cel_processed,
	        x.max_cel_id - y.last_cel_id 
	          AS Nb_cel_to_process
	    FROM
	      (SELECT max(id) AS max_cel_id FROM cel) x
	      NATURAL FULL JOIN
	      (SELECT id AS last_cel_id FROM last_cel_id) y'
	
	*                                                    *
	*  - Chat history was restored (if it is installed): *
	*    you can check xivo-upgrade log to verify if     *
	*    everything went well.                           *
	*
	*  - When you checked everything is ok, you should   *
	*    clean pgxivocc data:                            *
	*                                                    *
	*    rm -rf /var/lib/postgresql/xivouc/              *
	******************************************************
	EOF
}

if is_xivoucaddon; then
    display_ucaddon_upgrade_msg
fi
