From f658e115b3068e15cbf334b7728b20466e02a68e Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Thu, 11 Dec 2008 21:14:59 +0000 Subject: [PATCH] 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 --- upgrade.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/upgrade.php b/upgrade.php index 21451744..50a3aa66 100644 --- a/upgrade.php +++ b/upgrade.php @@ -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... +} +