diff --git a/root/etc/e-smith/templates/etc/e-smith/sql/init/80ejabberd b/root/etc/e-smith/templates/etc/e-smith/sql/init/80ejabberd index 8c718f4..54eb8f7 100644 --- a/root/etc/e-smith/templates/etc/e-smith/sql/init/80ejabberd +++ b/root/etc/e-smith/templates/etc/e-smith/sql/init/80ejabberd @@ -5,11 +5,19 @@ my $pass = ${'ejabberd'}{'DbPassword'} || 'secret'; $OUT .= <<"END"; #! /bin/sh +SCHEMA=\$(rpm -ql ejabberd | grep mysql.sql) if [ \! -d /var/lib/mysql/$db ]; then + # If database doesn't exists, create it and load the schema /usr/bin/mysqladmin create $db - for SQL in \$(rpm -qd ejabberd-modules | grep mysql.sql); do + /usr/bin/mysql $db < \$SCHEMA + for SQL in \$(rpm -qd ejabberd-modules | grep mod_archive_odbc_mysql.sql); do /usr/bin/mysql $db < \$SQL done +else + # If database exists, first drop actual indexes + grep -Pi '^CREATE(\ UNIQUE)?\ INDEX' \$SCHEMA | sed -e 's/CREATE/DROP/g' -e 's/(.*)//g' -e 's/USING BTREE //g' -e 's/UNIQUE //g' | /usr/bin/mysql -f $db + # and update the database (create missing tables and indexes) + sed -r -e 's/CREATE TABLE (.*) \\(/CREATE TABLE IF NOT EXISTS \\1 \\(/gi' \$SCHEMA | /usr/bin/mysql -f $db fi /usr/bin/mysql <