1
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2025-12-03 23:11:12 +03:00

upgrade.php: reindent; fix postgresql fetchmail stuff

git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@352 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
David Goodwin
2008-04-26 21:56:02 +00:00
parent 2814fd2ff7
commit 40417e9247

View File

@@ -320,8 +320,8 @@ function upgrade_1_mysql() {
} }
function upgrade_2_mysql() { function upgrade_2_mysql() {
# upgrade pre-2.1 database # upgrade pre-2.1 database
# from TABLE_BACKUP_MX.TXT # from TABLE_BACKUP_MX.TXT
$table_domain = table_by_key ('domain'); $table_domain = table_by_key ('domain');
$result = db_query_parsed("ALTER TABLE $table_domain ADD COLUMN transport VARCHAR(255) AFTER maxquota;", TRUE); $result = db_query_parsed("ALTER TABLE $table_domain ADD COLUMN transport VARCHAR(255) AFTER maxquota;", TRUE);
// don't think PGSQL supports 'AFTER transport' // don't think PGSQL supports 'AFTER transport'
@@ -539,56 +539,55 @@ function upgrade_4_pgsql() {
$result = db_query_parsed("ALTER TABLE $table_domain_admins ALTER COLUMN domain DROP DEFAULT"); $result = db_query_parsed("ALTER TABLE $table_domain_admins ALTER COLUMN domain DROP DEFAULT");
$result = db_query_parsed(" $result = db_query_parsed("
BEGIN; BEGIN;
ALTER TABLE $table_log RENAME COLUMN data TO data_old; ALTER TABLE $table_log RENAME COLUMN data TO data_old;
ALTER TABLE $table_log ADD COLUMN data 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); UPDATE $table_log SET data = CAST(data_old AS text);
ALTER TABLE $table_log DROP COLUMN data_old; ALTER TABLE $table_log DROP COLUMN data_old;
COMMIT;"); COMMIT;");
$result = db_query_parsed("ALTER TABLE $table_mailbox ALTER COLUMN username DROP DEFAULT"); $result = db_query_parsed("ALTER TABLE $table_mailbox ALTER COLUMN username DROP DEFAULT");
$result = db_query_parsed("ALTER TABLE $table_mailbox ALTER COLUMN domain DROP DEFAULT"); $result = db_query_parsed("ALTER TABLE $table_mailbox ALTER COLUMN domain DROP DEFAULT");
$result = db_query_parsed(" $result = db_query_parsed("
BEGIN; BEGIN;
ALTER TABLE $table_mailbox RENAME COLUMN domain TO domain_old; ALTER TABLE $table_mailbox RENAME COLUMN domain TO domain_old;
ALTER TABLE $table_mailbox ADD COLUMN domain varchar(255) REFERENCES domain (domain); ALTER TABLE $table_mailbox ADD COLUMN domain varchar(255) REFERENCES domain (domain);
UPDATE $table_mailbox SET domain = domain_old; UPDATE $table_mailbox SET domain = domain_old;
ALTER TABLE $table_mailbox DROP COLUMN domain_old; ALTER TABLE $table_mailbox DROP COLUMN domain_old;
COMMIT;" COMMIT;"
); );
if(!_pgsql_object_exists('mailbox_username_active')) { if(!_pgsql_object_exists('mailbox_username_active')) {
db_query_parsed('CREATE INDEX mailbox_username_active ON mailbox(username,active)'); db_query_parsed('CREATE INDEX mailbox_username_active ON mailbox(username,active)');
} }
$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 ''");
if(_pgsql_field_exists($table_vacation, 'cache')) { if(_pgsql_field_exists($table_vacation, 'cache')) {
$result = db_query_parsed("ALTER TABLE $table_vacation DROP COLUMN cache"); $result = db_query_parsed("ALTER TABLE $table_vacation DROP COLUMN cache");
} }
$result = db_query_parsed(" $result = db_query_parsed("
BEGIN; BEGIN;
ALTER TABLE $table_vacation RENAME COLUMN domain to domain_old; ALTER TABLE $table_vacation RENAME COLUMN domain to domain_old;
ALTER TABLE $table_vacation ADD COLUMN domain varchar(255) REFERENCES domain; ALTER TABLE $table_vacation ADD COLUMN domain varchar(255) REFERENCES domain;
UPDATE $table_vacation SET domain = domain_old; UPDATE $table_vacation SET domain = domain_old;
ALTER TABLE $table_vacation DROP COLUMN domain_old; ALTER TABLE $table_vacation DROP COLUMN domain_old;
COMMIT; COMMIT;
"); ");
if(!_pgsql_object_exists('vacation_email_active')) { if(!_pgsql_object_exists('vacation_email_active')) {
$result = db_query_parsed("CREATE INDEX vacation_email_active ON vacation(email,active)"); $result = db_query_parsed("CREATE INDEX vacation_email_active ON vacation(email,active)");
} }
if(!_pgsql_object_exists('vacation_notification')) { if(!_pgsql_object_exists('vacation_notification')) {
$result = db_query_parsed(" $result = db_query_parsed("
CREATE TABLE vacation_notification ( CREATE TABLE vacation_notification (
on_vacation character varying(255) NOT NULL REFERENCES vacation(email) ON DELETE CASCADE, on_vacation character varying(255) NOT NULL REFERENCES vacation(email) ON DELETE CASCADE,
notified character varying(255) NOT NULL, notified character varying(255) NOT NULL,
notified_at timestamp with time zone NOT NULL DEFAULT now(), notified_at timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT vacation_notification_pkey primary key(on_vacation,notified) CONSTRAINT vacation_notification_pkey primary key(on_vacation,notified));");
);"); }
}
} }
@@ -616,10 +615,9 @@ function upgrade_5_mysql() {
`active` tinyint(1) NOT NULL default '1', `active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`username`), PRIMARY KEY (`username`),
KEY username (`username`) KEY username (`username`)
) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Virtual Admins'; ) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Virtual Admins'; ");
");
$result = db_query_parsed(" $result = db_query_parsed("
CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('alias') . "` ( CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('alias') . "` (
`address` varchar(255) NOT NULL default '', `address` varchar(255) NOT NULL default '',
`goto` text NOT NULL, `goto` text NOT NULL,
@@ -628,11 +626,11 @@ $result = db_query_parsed("
`modified` datetime NOT NULL default '0000-00-00 00:00:00', `modified` datetime NOT NULL default '0000-00-00 00:00:00',
`active` tinyint(1) NOT NULL default '1', `active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`address`), PRIMARY KEY (`address`),
KEY address (`address`) KEY address (`address`)
) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Virtual Aliases'; ) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Virtual Aliases';
"); ");
$result = db_query_parsed(" $result = db_query_parsed("
CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('domain') . "` ( CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('domain') . "` (
`domain` varchar(255) NOT NULL default '', `domain` varchar(255) NOT NULL default '',
`description` varchar(255) NOT NULL default '', `description` varchar(255) NOT NULL default '',
@@ -646,11 +644,11 @@ $result = db_query_parsed("
`modified` datetime NOT NULL default '0000-00-00 00:00:00', `modified` datetime NOT NULL default '0000-00-00 00:00:00',
`active` tinyint(1) NOT NULL default '1', `active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`domain`), PRIMARY KEY (`domain`),
KEY domain (`domain`) KEY domain (`domain`)
) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Virtual Domains'; ) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Virtual Domains';
"); ");
$result = db_query_parsed(" $result = db_query_parsed("
CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('domain_admins') . "` ( CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('domain_admins') . "` (
`username` varchar(255) NOT NULL default '', `username` varchar(255) NOT NULL default '',
`domain` varchar(255) NOT NULL default '', `domain` varchar(255) NOT NULL default '',
@@ -658,9 +656,9 @@ $result = db_query_parsed("
`active` tinyint(1) NOT NULL default '1', `active` tinyint(1) NOT NULL default '1',
KEY username (`username`) KEY username (`username`)
) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Domain Admins'; ) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Domain Admins';
"); ");
$result = db_query_parsed(" $result = db_query_parsed("
CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('log') . "` ( CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('log') . "` (
`timestamp` datetime NOT NULL default '0000-00-00 00:00:00', `timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
`username` varchar(255) NOT NULL default '', `username` varchar(255) NOT NULL default '',
@@ -669,9 +667,9 @@ $result = db_query_parsed("
`data` varchar(255) NOT NULL default '', `data` varchar(255) NOT NULL default '',
KEY timestamp (`timestamp`) KEY timestamp (`timestamp`)
) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Log'; ) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Log';
"); ");
$result = db_query_parsed(" $result = db_query_parsed("
CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('mailbox') . "` ( CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('mailbox') . "` (
`username` varchar(255) NOT NULL default '', `username` varchar(255) NOT NULL default '',
`password` varchar(255) NOT NULL default '', `password` varchar(255) NOT NULL default '',
@@ -683,11 +681,11 @@ $result = db_query_parsed("
`modified` datetime NOT NULL default '0000-00-00 00:00:00', `modified` datetime NOT NULL default '0000-00-00 00:00:00',
`active` tinyint(1) NOT NULL default '1', `active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`username`), PRIMARY KEY (`username`),
KEY username (`username`) KEY username (`username`)
) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Virtual Mailboxes'; ) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Virtual Mailboxes';
"); ");
$result = db_query_parsed(" $result = db_query_parsed("
CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('vacation') . "` ( CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('vacation') . "` (
`email` varchar(255) NOT NULL default '', `email` varchar(255) NOT NULL default '',
`subject` varchar(255) NOT NULL default '', `subject` varchar(255) NOT NULL default '',
@@ -697,9 +695,9 @@ $result = db_query_parsed("
`created` datetime NOT NULL default '0000-00-00 00:00:00', `created` datetime NOT NULL default '0000-00-00 00:00:00',
`active` tinyint(1) NOT NULL default '1', `active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`email`), PRIMARY KEY (`email`),
KEY email (`email`) KEY email (`email`)
) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Virtual Vacation'; ) TYPE=MyISAM DEFAULT {LATIN1} COMMENT='Postfix Admin - Virtual Vacation';
"); ");
} }
/** /**
@@ -773,32 +771,31 @@ function upgrade_318_mysql() {
PRIMARY KEY on_vacation (`on_vacation`, `notified`), PRIMARY KEY on_vacation (`on_vacation`, `notified`),
CONSTRAINT `vacation_notification_pkey` CONSTRAINT `vacation_notification_pkey`
FOREIGN KEY (`on_vacation`) REFERENCES vacation(`email`) ON DELETE CASCADE FOREIGN KEY (`on_vacation`) REFERENCES vacation(`email`) ON DELETE CASCADE
) )
ENGINE=InnoDB DEFAULT {LATIN1} TYPE=InnoDB ENGINE=InnoDB DEFAULT {LATIN1} TYPE=InnoDB
COMMENT='Postfix Admin - Virtual Vacation Notifications' COMMENT='Postfix Admin - Virtual Vacation Notifications'
"); ");
# in case someone has manually created the table with utf8 fields before: # in case someone has manually created the table with utf8 fields before:
$all_sql = split("\n", trim(" $all_sql = split("\n", trim("
ALTER TABLE `$table_vacation_notification` DROP FOREIGN KEY `vacation_notification_pkey` ALTER TABLE `$table_vacation_notification` DROP FOREIGN KEY `vacation_notification_pkey`
ALTER TABLE `$table_vacation_notification` CHANGE `on_vacation` `on_vacation` VARCHAR( 255 ) {LATIN1} NOT NULL ALTER TABLE `$table_vacation_notification` CHANGE `on_vacation` `on_vacation` VARCHAR( 255 ) {LATIN1} NOT NULL
ALTER TABLE `$table_vacation_notification` CHANGE `notified` `notified` VARCHAR( 255 ) {LATIN1} NOT NULL ALTER TABLE `$table_vacation_notification` CHANGE `notified` `notified` VARCHAR( 255 ) {LATIN1} NOT NULL
ALTER TABLE `$table_vacation_notification` DEFAULT {LATIN1} ALTER TABLE `$table_vacation_notification` DEFAULT {LATIN1}
")); "));
# Possible errors that can be ignored: # Possible errors that can be ignored:
# None. # None.
# If something goes wrong, the user should drop the vacation_notification table # If something goes wrong, the user should drop the vacation_notification table
# (not a great loss) and re-create it using this function. # (not a great loss) and re-create it using this function.
foreach ($all_sql as $sql) { foreach ($all_sql as $sql) {
$result = db_query_parsed($sql); $result = db_query_parsed($sql);
} }
# create constraint... # create constraint...
$result = db_query_parsed(" $result = db_query_parsed("
ALTER TABLE $table_vacation_notification ADD CONSTRAINT `vacation_notification_pkey` ALTER TABLE $table_vacation_notification ADD CONSTRAINT `vacation_notification_pkey`
FOREIGN KEY (`on_vacation`) REFERENCES vacation(`email`) ON DELETE CASCADE FOREIGN KEY (`on_vacation`) REFERENCES vacation(`email`) ON DELETE CASCADE ");
");
} }
@@ -807,10 +804,10 @@ $result = db_query_parsed("
*/ */
function upgrade_344_mysql() { function upgrade_344_mysql() {
$table_vacation_notification = table_by_key('vacation_notification'); $table_fetchmail = table_by_key('fetchmail');
db_query_parsed( " db_query_parsed( "
create table fetchmail( create table $table_fetchmail(
id int(11) unsigned not null auto_increment, id int(11) unsigned not null auto_increment,
mailbox varchar(255) not null default '', mailbox varchar(255) not null default '',
src_server varchar(255) not null default '', src_server varchar(255) not null default '',
@@ -832,6 +829,38 @@ function upgrade_344_mysql() {
} }
function upgrade_344_pgsql() { function upgrade_344_pgsql() {
# TODO: create fetchmail table for PgSQL $fetchmail = table_by_key('fetchmail');
// a field name called 'date' is probably a bad idea.
if(!_pgsql_object_exists('fetchmail')) {
db_query_parsed( "
create table $fetchmail(
id serial,
mailbox varchar(255) not null default '',
src_server varchar(255) not null default '',
src_auth varchar(15) NOT NULL,
src_user varchar(255) not null default '',
src_password varchar(255) not null default '',
src_folder varchar(255) not null default '',
poll_time integer not null default 10,
fetchall boolean not null default false,
keep boolean not null default false,
protocol varchar(15) NOT NULL,
extra_options text,
returned_text text,
mda varchar(255) not null default '',
date timestamp with time zone default now(),
primary key(id),
CHECK (src_auth IN ('password','kerberos_v5','kerberos','kerberos_v4','gssapi','cram-md5','otp','ntlm','msn','ssh','any')),
CHECK (protocol IN ('POP3', 'IMAP', 'POP2', 'ETRN', 'AUTO'))
);
");
}
// MySQL expects sequences to start at 1. Stupid database.
// fetchmail.php requires id parameters to be > 0, as it does if($id) like logic... hence if we don't
// fudge the sequence starting point, you cannot delete/edit the first entry if using PostgreSQL.
// I'm sure there's a more elegant way of fixing it properly.... but this should work for now.
if(_pgsql_object_exists('fetchmail_id_seq')) {
db_query_parsed("SELECT nextval('{$fetchmail}_id_seq')"); // I don't care about number waste.
}
} }