#!/bin/sh

# This script generates the database upgrade files for dbconfig for
# Bacula 11. It is intended to be run once, manually and the generated
# files to be committed to git.

patch -p1 < debian/scripts/help_database_update_scripts_extractor_v13.patch

sed -i '/.*END-OF-DATA/s/mysql[^<]*/grep -v ^USE >> $OUTFILE /' src/cats/update_mysql_tables.in
OUTFILE=debian/additions/mysql/database/upgrade/13.0.0 DBVERSION=16 sh src/cats/update_mysql_tables.in

## For postgres this strategy doesn't work, the upgrade script for
## postgres from Bacula 9.x to 11.x involves dumping the file table
## and reading it back. The patch above includes removal of the update
## 1017. The file for update 1017 was created manually.
##
sed -i '/.*\E[ND-]*OF[-DATA]*/s/[! ]*psql[^<]*/ cat >> $OUTFILE /' src/cats/update_postgresql_tables.in
OUTFILE=debian/additions/pgsql/database/upgrade/13.0.0 DBVERSION=16 sh src/cats/update_postgresql_tables.in

sed -i '/.*END-OF-DATA/s/sqlite3[^<]*/cat >> $OUTFILE /' src/cats/update_sqlite3_tables.in
OUTFILE=debian/additions/sqlite3/database/upgrade/13.0.0 DBVERSION=16 sh src/cats/update_sqlite3_tables.in
