#!/bin/bash

# postgresql patch uses load_file function that only seems to be available on
#   mysql, thus it most likely will fail anyway

# this script compiles all individual patches in a single patch (correctly
#   ordered) and replaces relative path to images with an absolute one
#   (mysql does not seem to like relative paths much)

cd $(dirname $0)

for database in mysql; do
	[[ -f "$database.sql" ]] && rm "$database.sql"
	for version in $(ls -d */ | sort -k1,1 -t a -k2,2n -k3,3n); do
		cat $version/$database/patch.sql | sed "s#load_file(\"#load_file(\"$PWD/1.0_to_1.1alpha1/mysql/#" >> $database.sql
	done
done
