From abfc5ae5dac71fcce68354e67bc84d74f3d8c33f Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 28 Sep 2012 12:44:27 +0200 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20des=20tables=20manquantes=20dur?= =?UTF-8?q?ant=20les=20mises=20=C3=A0=20jour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- root/etc/e-smith/templates/etc/e-smith/sql/init/80ejabberd | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 <