#!/usr/bin/env bash

# Copyright © 2012-2026 ScriptFanix
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# A copy of the GNU General Public License v3 is includded in the LICENSE file
# at the root of the project.

upgradedatabase_6_7() {
	echo "Upgrading database to version 7... (backup is $database.bak_v6)"
        cp "$database" "$database.bak_v6"
        # In v6 and earlier, destination_files.filename stored absolute paths.
        # From v7 onwards, filenames are stored relative to the destination
        # root.
        # Strip the destination path prefix from all stored filenames.
        for destination in "${destinations[@]}"
        do
                echo "UPDATE destination_files SET filename = REPLACE(filename,'${destinationpath[$destination]}/','') WHERE filename LIKE '${destinationpath[$destination]}/%';" >&3
        done
        Update atom version 7 <<<"1 = 1"
}
