upgrade.php: first part of adding support for local_part of a mailboxs address - see https://sourceforge.net/forum/forum.php?thread_id=2343775&forum_id=676076

git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@495 a1433add-5e2c-0410-b055-b7f2511e0802
postfixadmin-2.3
David Goodwin 17 years ago
parent 4df62240fd
commit f658e115b3

@ -41,7 +41,6 @@ function _pgsql_field_exists($table, $field) {
AND pg_catalog.pg_table_is_visible(c.oid)
)
AND a.attname = '$field' ";
// echo $sql;
$r = db_query($sql);
$row = db_row($r['result']);
if($row) {
@ -1006,3 +1005,22 @@ function upgrade_483_mysql () {
db_query_parsed("ALTER TABLE $table_log CHANGE `data` `data` TEXT {LATIN1} NOT NULL");
}
# Add a local_part field to the mailbox table, and populate it with the local part of the user's address.
# This is to make it easier (hopefully) to change the filesystem location of a mailbox in the future
# See https://sourceforge.net/forum/message.php?msg_id=5394663
function upgrade_495_pgsql() {
$table_mailbox = table_by_key('mailbox');
if(!_pgsql_field_exists($table_mailbox, 'local_part')) {
db_query_parsed("ALTER TABLE $table_mailbox add column local_part varchar(255) ");
db_query_parsed("UPDATE $table_mailbox SET local_part = substring(username from '^(.*)@')");
db_query_parsed("ALTER TABLE $table_mailbox alter column local_part SET NOT NULL");
}
}
# See https://sourceforge.net/forum/message.php?msg_id=5394663
function upgrade_495_mysql() {
$table_mailbox = table_by_key('mailbox');
db_query_parsed("ALTER TABLE $table_mailbox add local_part varchar(255) "); // allow to be null
db_query_parsed("UPDATE $table_mailbox SET local_part = substring_index(username, '@', 1");
db_query_parsed("ALTER TABLE $table_mailbox change local_part local_part varchar(255) NOT NULL"); // remove null-ness...
}

Loading…
Cancel
Save