|
|
|
@ -4,11 +4,24 @@ require_once('common.php');
|
|
|
|
|
# Note: run with upgrade.php?debug=1 to see all SQL error messages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Not nice, but works:
|
|
|
|
|
# We don't know if the config table exists, so we simply try to create it ;-)
|
|
|
|
|
# Better solution (TODO): query the db to see if the 'config' table exists
|
|
|
|
|
|
|
|
|
|
$sql = "
|
|
|
|
|
|
|
|
|
|
if($CONF['database_type'] == 'pgsql') {
|
|
|
|
|
// check if table already exists, if so, don't recreate it
|
|
|
|
|
$r = db_query("SELECT relname FROM pg_class WHERE relname = 'config'");
|
|
|
|
|
if($r['rows'] == 0) {
|
|
|
|
|
$pgsql = "
|
|
|
|
|
CREATE TABLE config (
|
|
|
|
|
id SERIAL,
|
|
|
|
|
name VARCHAR(20) NOT NULL UNIQUE,
|
|
|
|
|
value VARCHAR(20) NOT NULL,
|
|
|
|
|
PRIMARY KEY(id)
|
|
|
|
|
)";
|
|
|
|
|
db_query_parsed($pgsql);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$mysql = "
|
|
|
|
|
CREATE TABLE {IF_NOT_EXISTS} " . table_by_key ('config') . "(
|
|
|
|
|
`id` {AUTOINCREMENT} {PRIMARY},
|
|
|
|
|
`name` VARCHAR(20) {LATIN1} NOT NULL DEFAULT '',
|
|
|
|
@ -16,8 +29,8 @@ CREATE TABLE {IF_NOT_EXISTS} " . table_by_key ('config') . "(
|
|
|
|
|
UNIQUE name ( `name` )
|
|
|
|
|
)
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
db_query_parsed($sql, 0, " ENGINE = MYISAM COMMENT = 'PostfixAdmin settings'");
|
|
|
|
|
db_query_parsed($mysql, 0, " ENGINE = MYISAM COMMENT = 'PostfixAdmin settings'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM config WHERE name = 'version'";
|
|
|
|
|
|
|
|
|
@ -32,6 +45,7 @@ if($r['rows'] == 1) {
|
|
|
|
|
} else {
|
|
|
|
|
$version = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_do_upgrade($version);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -69,15 +83,17 @@ function _do_upgrade($current_version) {
|
|
|
|
|
echo " done";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# TODO: update version in config table after each change
|
|
|
|
|
# TODO: this avoids problems in case the script hits the max_execution_time,
|
|
|
|
|
# TODO: simply rerunning it will continue where it was stopped
|
|
|
|
|
// Update config table so we don't run the same query twice in the future.
|
|
|
|
|
$i = (int) $i;
|
|
|
|
|
$sql = "UPDATE config SET value = $i WHERE name = 'version'";
|
|
|
|
|
db_query($sql);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Replaces database specific parts in a query
|
|
|
|
|
* @param String sql query with placeholders
|
|
|
|
|
* @param int (optional) whether errors should be ignored (0=false)
|
|
|
|
|
* @param String (optional) MySQL specific code to attach, useful for COMMENT= on CREATE TABLE
|
|
|
|
|
* @return String sql query
|
|
|
|
|
*/
|
|
|
|
@ -173,7 +189,6 @@ function upgrade_2_pgsql() {
|
|
|
|
|
$table_domain = table_by_key ('domain');
|
|
|
|
|
$result = db_query_parsed("ALTER TABLE $table_domain ADD COLUMN transport VARCHAR(255)", TRUE);
|
|
|
|
|
$result = db_query_parsed("ALTER TABLE $table_domain ADD COLUMN backupmx BOOLEAN DEFAULT false", TRUE);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function upgrade_3_mysql() {
|
|
|
|
@ -247,7 +262,7 @@ function upgrade_4_pgsql() { # PgSQL only
|
|
|
|
|
|
|
|
|
|
$result = db_query_parsed("BEGIN;
|
|
|
|
|
ALTER TABLE $table_log RENAME COLUMN data TO data_old;
|
|
|
|
|
ALTER TABLE $table_log ADD COLUMN data TYPE text NOT NULL default '';
|
|
|
|
|
ALTER TABLE $table_log ADD COLUMN data text NOT NULL default '';
|
|
|
|
|
UPDATE $table_log SET data = CAST(data_old AS text);
|
|
|
|
|
ALTER TABLE $table_log DROP COLUMN data_old;
|
|
|
|
|
COMMIT;");
|
|
|
|
@ -264,7 +279,7 @@ function upgrade_4_pgsql() { # PgSQL only
|
|
|
|
|
COMMIT;");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = db_query_parsed("ALTER TABLE $table_vacation ALTER COLUMN body SET DEFAULT = ''");
|
|
|
|
|
$result = db_query_parsed("ALTER TABLE $table_vacation ALTER COLUMN body SET DEFAULT ''");
|
|
|
|
|
$result = db_query_parsed("ALTER TABLE $table_vacation DROP COLUMN cache");
|
|
|
|
|
|
|
|
|
|
$result = db_query_parsed("ALTER TABLE $table_vacation RENAME COLUMN domain to domain_old");
|
|
|
|
@ -365,4 +380,3 @@ MySQL:
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|
|
|
|
|