#!/bin/bash # database-update.sh # OpenLog Online Logbook # Copyright (C) 2025 Rod Wright # SPDX-License-Identifier: GPL-2.0 if [[ $1 == "" ]] then echo "This script requires a mysql options file, but none was specified. Aborting." exit 1 fi mysql_opt_file=$1 if [[ ! -f $mysql_opt_file ]] then echo "The mysql options file specified does not exist. Aborting." exit 1 fi margs="--defaults-extra-file=$mysql_opt_file" # ---------- version x.x.x ---------- # Nothing to be done for versions prior to 5.2.4.3 # ----------------------------------- # ---------- version 5.2.4.3 ---------- # Nothing to do # ------------------------------------- # ---------- version 5.2.4.4 ---------- # Nothing to do # ------------------------------------- # ---------- version 5.2.5 ------------ # Nothing to do # ------------------------------------- # ---------- version 5.3.0 ------------ # echo "Started database updates for OpenLog version 5.3.0..." # Import old flag data from old scheme to new flagmap table if [[ $(mysql $margs -e "select count(*) from flagmap") == 0 ]] then echo "Importing flag data from old scheme to new flagmap table..." for flagnumber in $(mysql $margs -e "select flagid from flags") do flag_x=$(mysql $margs -s -e "show tables like 'flag_$flagnumber'") if [[ -n "$flag_x" ]] then for tgtid in $(mysql $margs -e "select id from flag_$flagnumber") do target=$(mysql $margs -e "select target from flag_$flagnumber where id=$tgtid") if [[ $target == "lognotes" ]] then mysql $margs -e "insert into flagmap(flagid,lognoteid) values($flagnumber,$tgtid)" elif [[ $target == "maintforms" ]] then mysql $margs -e "insert into flagmap(flagid,maintformid) values($flagnumber,$tgtid)" elif [[ $target == "notetemplates" ]] then mysql $margs -e "insert into flagmap(flagid,notetemplateid) values($flagnumber,$tgtid)" fi done mysql $margs -e "drop table flag_$flagnumber" fi done echo "...done." fi # Import reference chain data into new reflinks table if [[ $(mysql $margs -e "select count(*) from reflinks") == 0 ]] then echo "Importing lognote reference chain data into new reflinks table..." for note in $(mysql $margs -e "select lognoteid from lognotes where refs!=''") do refstring=$(mysql $margs -e "select refs from lognotes where lognoteid=$note") oldifs=$IFS IFS=', ' for target in $refstring do target=$(echo "$target" | xargs) mysql $margs -e "insert into reflinks(noteid,target) values($note,$target)" done IFS=$oldifs done echo "...done." echo "Importing template reference chain data into new reflinks table..." for template in $(mysql $margs -e "select templateid from notetemplates where refs!=''") do refstring=$(mysql $margs -e "select refs from notetemplates where templateid=$template") oldifs=$IFS IFS=', ' for target in $refstring do target=$(echo "$target" | xargs) mysql $margs -e "insert into reflinks(templateid,target) values($template,$target)" done IFS=$oldifs done echo "...done." mysql $margs -e "alter table lognotes drop column refs" >/dev/null 2>&1 mysql $margs -e "alter table notetemplates drop column refs" >/dev/null 2>&1 fi # Convert database to utf8mb4/utf8mb4_unicode_ci echo "Converting database to utf8mb4 encoding..." mysql $margs -e "ALTER DATABASE CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci" for table in $(mysql $margs -e "show tables") do mysql $margs -e "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" done echo "...done." # -------------------------------------