Thread: SF.net SVN: postfixadmin:[1685] trunk/upgrade.php (Page 3)
Brought to you by:
christian_boltz,
gingerdog
|
From: <chr...@us...> - 2014-09-12 09:47:32
|
Revision: 1685
http://sourceforge.net/p/postfixadmin/code/1685
Author: christian_boltz
Date: 2014-09-12 09:47:22 +0000 (Fri, 12 Sep 2014)
Log Message:
-----------
upgrade.php:
- upgrade_1685_mysql()/upgrade_1685_pgsql:
Fix existing log entries broken by
https://sourceforge.net/p/postfixadmin/bugs/317/
Modified Paths:
--------------
trunk/upgrade.php
Modified: trunk/upgrade.php
===================================================================
--- trunk/upgrade.php 2014-09-12 09:22:09 UTC (rev 1684)
+++ trunk/upgrade.php 2014-09-12 09:47:22 UTC (rev 1685)
@@ -1347,6 +1347,19 @@
_db_add_field('vacation', 'interval_time', '{INT}', 'domain');
}
+function upgrade_1685_mysql() {
+ # Fix existing log entries broken by https://sourceforge.net/p/postfixadmin/bugs/317/
+ $table = table_by_key('log');
+ db_query_parsed("UPDATE $table SET data = domain WHERE data = '' AND domain LIKE '%@%'");
+ db_query_parsed("UPDATE $table SET domain=SUBSTRING_INDEX(domain, '@', -1) WHERE domain=data;");
+}
+function upgrade_1685_pgsql() {
+ $table = table_by_key('log');
+ db_query_parsed("UPDATE $table SET data = domain WHERE data = '' AND domain LIKE '%@%'");
+ db_query_parsed("UPDATE $table SET domain=SPLIT_PART(domain, '@', 2) WHERE domain=data;");
+}
+
+
# TODO MySQL:
# - various varchar fields do not have a default value
# https://sourceforge.net/projects/postfixadmin/forums/forum/676076/topic/3419725
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gin...@us...> - 2015-02-17 11:03:19
|
Revision: 1740
http://sourceforge.net/p/postfixadmin/code/1740
Author: gingerdog
Date: 2015-02-17 11:03:16 +0000 (Tue, 17 Feb 2015)
Log Message:
-----------
stop relying on subversion keyword for database upgrades; just iterate over all user defined functions and find the largest numeric one
Modified Paths:
--------------
trunk/upgrade.php
Modified: trunk/upgrade.php
===================================================================
--- trunk/upgrade.php 2015-02-16 14:43:58 UTC (rev 1739)
+++ trunk/upgrade.php 2015-02-17 11:03:16 UTC (rev 1740)
@@ -135,11 +135,21 @@
_do_upgrade($version);
-
function _do_upgrade($current_version) {
global $CONF;
- $target_version = preg_replace('/[^0-9]/', '', '$Revision$');
+ $target_version = 0;
+ // Rather than being bound to an svn revision number, just look for the largest function name that matches upgrade_\d+...
+ // $target_version = preg_replace('/[^0-9]/', '', '$Revision$');
+ $our_upgrade_functions = array_filter(get_defined_functions()['user'], function($name) { return preg_match('/upgrade_[\d]+(_mysql|_pgsql)?$/', $name) == 1; } );
+ foreach($our_upgrade_functions as $function_name) {
+ $bits = explode("_", $function_name);
+ $function_number = $bits[1];
+ if($function_number > $current_version && $function_number > $target_version) {
+ $target_version = $function_number;
+ }
+ }
+
if ($current_version >= $target_version) {
# already up to date
echo "<p>Database is up to date</p>";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2015-04-04 14:20:59
|
Revision: 1763
http://sourceforge.net/p/postfixadmin/code/1763
Author: christian_boltz
Date: 2015-04-04 14:20:57 +0000 (Sat, 04 Apr 2015)
Log Message:
-----------
Two upgrades for FetchmailHandler:
- upgrade_1762: add 'domain', 'active', 'created' and 'modified' fields
to fetchmail table (used by FetchmailHandler)
- upgrade_1763: fill fetchmail.domain based on mailbox
Modified Paths:
--------------
trunk/upgrade.php
Modified: trunk/upgrade.php
===================================================================
--- trunk/upgrade.php 2015-04-04 13:58:42 UTC (rev 1762)
+++ trunk/upgrade.php 2015-04-04 14:20:57 UTC (rev 1763)
@@ -1369,7 +1369,19 @@
db_query_parsed("UPDATE $table SET domain=SPLIT_PART(domain, '@', 2) WHERE domain=data;");
}
+function upgrade_1762() {
+ _db_add_field('fetchmail', 'domain', "VARCHAR(255) {LATIN1} DEFAULT ''", 'id');
+ _db_add_field('fetchmail', 'active', '{BOOLEAN}', 'date');
+ _db_add_field('fetchmail', 'created', '{DATE}', 'date');
+ _db_add_field('fetchmail', 'modified', '{DATECURRENT}', 'created');
+}
+function upgrade_1763() {
+ $table = table_by_key('fetchmail');
+ db_query_parsed("UPDATE $table SET domain=SUBSTRING_INDEX(mailbox, '@', -1) WHERE domain='';");
+}
+
+
# TODO MySQL:
# - various varchar fields do not have a default value
# https://sourceforge.net/projects/postfixadmin/forums/forum/676076/topic/3419725
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2015-04-04 14:33:00
|
Revision: 1767
http://sourceforge.net/p/postfixadmin/code/1767
Author: christian_boltz
Date: 2015-04-04 14:32:58 +0000 (Sat, 04 Apr 2015)
Log Message:
-----------
upgrade_1767: fetchmail.active field was just added. Make sure all
existing fetchmail jobs are active.
Modified Paths:
--------------
trunk/upgrade.php
Modified: trunk/upgrade.php
===================================================================
--- trunk/upgrade.php 2015-04-04 14:26:21 UTC (rev 1766)
+++ trunk/upgrade.php 2015-04-04 14:32:58 UTC (rev 1767)
@@ -1381,7 +1381,13 @@
db_query_parsed("UPDATE $table SET domain=SUBSTRING_INDEX(mailbox, '@', -1) WHERE domain='';");
}
+function upgrade_1767() {
+ # 'active' was just added, so make sure all existing jobs stay active
+ $table = table_by_key('fetchmail');
+ db_query_parsed("UPDATE $table SET active='{BOOL_TRUE}'");
+}
+
# TODO MySQL:
# - various varchar fields do not have a default value
# https://sourceforge.net/projects/postfixadmin/forums/forum/676076/topic/3419725
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2015-05-06 21:34:17
|
Revision: 1786
http://sourceforge.net/p/postfixadmin/code/1786
Author: christian_boltz
Date: 2015-05-06 21:34:14 +0000 (Wed, 06 May 2015)
Log Message:
-----------
upgrade.php:
- split upgrade_1763() into mysql and pgsql versions because pgsql
doesn't support SUBSTRING_INDEX
(reported by darix on IRC)
Modified Paths:
--------------
trunk/upgrade.php
Modified: trunk/upgrade.php
===================================================================
--- trunk/upgrade.php 2015-04-26 19:25:43 UTC (rev 1785)
+++ trunk/upgrade.php 2015-05-06 21:34:14 UTC (rev 1786)
@@ -1376,10 +1376,14 @@
_db_add_field('fetchmail', 'modified', '{DATECURRENT}', 'created');
}
-function upgrade_1763() {
+function upgrade_1763_mysql() {
$table = table_by_key('fetchmail');
db_query_parsed("UPDATE $table SET domain=SUBSTRING_INDEX(mailbox, '@', -1) WHERE domain='';");
}
+function upgrade_1763_pgsql() {
+ $table = table_by_key('fetchmail');
+ db_query_parsed("UPDATE $table SET domain=SPLIT_PART(mailbox, '@', 2) WHERE domain='';");
+}
function upgrade_1767() {
# 'active' was just added, so make sure all existing jobs stay active
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2015-09-07 20:46:34
|
Revision: 1795
http://sourceforge.net/p/postfixadmin/code/1795
Author: christian_boltz
Date: 2015-09-07 20:46:31 +0000 (Mon, 07 Sep 2015)
Log Message:
-----------
upgrade.php:
- change fetchmail.date from DATECURRENT to date
https://sourceforge.net/p/postfixadmin/bugs/351/
Modified Paths:
--------------
trunk/upgrade.php
Modified: trunk/upgrade.php
===================================================================
--- trunk/upgrade.php 2015-09-06 21:47:34 UTC (rev 1794)
+++ trunk/upgrade.php 2015-09-07 20:46:31 UTC (rev 1795)
@@ -1369,10 +1369,21 @@
db_query_parsed("UPDATE $table SET domain=SPLIT_PART(domain, '@', 2) WHERE domain=data;");
}
+function upgrade_1761_mysql() {
+ # upgrade_1762 adds the 'modified' column as {DATECURRENT}, therefore we first need to change
+ # 'date' to {DATE} (mysql only allows one {DATECURRENT} column per table)
+ $table_fetchmail = table_by_key('fetchmail');
+ db_query_parsed("ALTER TABLE `$table_fetchmail` CHANGE `date` `date` {DATE}");
+}
+
function upgrade_1762() {
_db_add_field('fetchmail', 'domain', "VARCHAR(255) {LATIN1} DEFAULT ''", 'id');
_db_add_field('fetchmail', 'active', '{BOOLEAN}', 'date');
_db_add_field('fetchmail', 'created', '{DATE}', 'date');
+
+ # If you followed SVN and got upgrade failures here, you might need to
+ # UPDATE config SET value=1760 WHERE name='version';
+ # and run setup.php again (upgrade_1761_mysql was added later).
_db_add_field('fetchmail', 'modified', '{DATECURRENT}', 'created');
}
@@ -1391,6 +1402,11 @@
db_query_parsed("UPDATE $table SET active='{BOOL_TRUE}'");
}
+function upgrade_1795_mysql() {
+ # upgrade_1761_mysql() was added later (in r1795) - make sure it runs for everybody
+ # (running it twice doesn't hurt)
+ upgrade_1761_mysql();
+}
# TODO MySQL:
# - various varchar fields do not have a default value
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gin...@us...> - 2015-09-18 05:10:16
|
Revision: 1798
http://sourceforge.net/p/postfixadmin/code/1798
Author: gingerdog
Date: 2015-09-18 05:10:13 +0000 (Fri, 18 Sep 2015)
Log Message:
-----------
try and support older versions of PHP (e.g 5.3) which do not support closures etc
Modified Paths:
--------------
trunk/upgrade.php
Modified: trunk/upgrade.php
===================================================================
--- trunk/upgrade.php 2015-09-08 04:45:31 UTC (rev 1797)
+++ trunk/upgrade.php 2015-09-18 05:10:13 UTC (rev 1798)
@@ -71,6 +71,9 @@
return _mysql_field_exists($table, $field);
}
}
+function _upgrade_filter_function($name) {
+ return preg_match('/upgrade_[\d]+(_mysql|_pgsql)?$/', $name) == 1;
+}
function _db_add_field($table, $field, $fieldtype, $after) {
global $CONF;
@@ -141,7 +144,8 @@
$target_version = 0;
// Rather than being bound to an svn revision number, just look for the largest function name that matches upgrade_\d+...
// $target_version = preg_replace('/[^0-9]/', '', '$Revision$');
- $our_upgrade_functions = array_filter(get_defined_functions()['user'], function($name) { return preg_match('/upgrade_[\d]+(_mysql|_pgsql)?$/', $name) == 1; } );
+ $funclist = get_defined_functions();
+ $our_upgrade_functions = array_filter($funclist['user'], '_upgrade_filter_function');
foreach($our_upgrade_functions as $function_name) {
$bits = explode("_", $function_name);
$function_number = $bits[1];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2016-04-25 21:20:27
|
Revision: 1835
http://sourceforge.net/p/postfixadmin/code/1835
Author: christian_boltz
Date: 2016-04-25 21:20:25 +0000 (Mon, 25 Apr 2016)
Log Message:
-----------
upgrade.php:
- change default date for 'created' and 'updated' columns from
0000-00-00 (which causes problems with MySQL strict mode) to
2000-01-01. This is done with a new {DATETIME} marker to reduce
code duplication.
- add upgrade_1835_mysql() to apply the same change to existing
databases
This fixes
https://sourceforge.net/p/postfixadmin/bugs/5/ and
https://sourceforge.net/p/postfixadmin/bugs/373/
(which are effectively duplicates)
Modified Paths:
--------------
trunk/upgrade.php
Modified: trunk/upgrade.php
===================================================================
--- trunk/upgrade.php 2016-04-25 11:23:35 UTC (rev 1834)
+++ trunk/upgrade.php 2016-04-25 21:20:25 UTC (rev 1835)
@@ -251,6 +251,7 @@
'{INNODB}' => 'ENGINE=InnoDB',
'{INT}' => 'integer NOT NULL DEFAULT 0',
'{BIGINT}' => 'bigint NOT NULL DEFAULT 0',
+ '{DATETIME}' => "datetime NOT NULL default '2000-01-01 00:00:00'", # different from {DATE} only for MySQL
'{DATE}' => "timestamp NOT NULL default '2000-01-01'", # MySQL needs a sane default (no default is interpreted as CURRENT_TIMESTAMP, which is ...
'{DATECURRENT}' => 'timestamp NOT NULL default CURRENT_TIMESTAMP', # only allowed once per table in MySQL
);
@@ -272,6 +273,7 @@
'{INNODB}' => '',
'{INT}' => 'int(11) NOT NULL DEFAULT 0',
'{BIGINT}' => 'bigint(20) NOT NULL DEFAULT 0',
+ '{DATETIME}' => "datetime NOT NULL default '2000-01-01'",
'{DATE}' => "datetime NOT NULL default '2000-01-01'",
'{DATECURRENT}' => 'datetime NOT NULL default CURRENT_TIMESTAMP',
);
@@ -294,6 +296,7 @@
'int(10)' => 'int',
'int(11)' => 'int',
'int(4)' => 'int',
+ '{DATETIME}' => "timestamp with time zone default '2000-01-01'", # stay in sync with MySQL
'{DATE}' => "timestamp with time zone default '2000-01-01'", # stay in sync with MySQL
'{DATECURRENT}' => 'timestamp with time zone default now()',
);
@@ -364,8 +367,8 @@
CREATE TABLE {IF_NOT_EXISTS} $admin (
`username` varchar(255) NOT NULL default '',
`password` varchar(255) NOT NULL default '',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
- `modified` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
+ `modified` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`username`)
) {MYISAM} COMMENT='Postfix Admin - Virtual Admins';";
@@ -375,8 +378,8 @@
`address` varchar(255) NOT NULL default '',
`goto` text NOT NULL,
`domain` varchar(255) NOT NULL default '',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
- `modified` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
+ `modified` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`address`)
) {MYISAM} COMMENT='Postfix Admin - Virtual Aliases'; ";
@@ -391,8 +394,8 @@
`quota` bigint(20) NOT NULL default '0',
`transport` varchar(255) default NULL,
`backupmx` tinyint(1) NOT NULL default '0',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
- `modified` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
+ `modified` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`domain`)
) {MYISAM} COMMENT='Postfix Admin - Virtual Domains'; ";
@@ -401,14 +404,14 @@
CREATE TABLE {IF_NOT_EXISTS} $domain_admins (
`username` varchar(255) NOT NULL default '',
`domain` varchar(255) NOT NULL default '',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
KEY username (`username`)
) {MYISAM} COMMENT='Postfix Admin - Domain Admins';";
$sql[] = "
CREATE TABLE {IF_NOT_EXISTS} $log (
- `timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
+ `timestamp` {DATETIME},
`username` varchar(255) NOT NULL default '',
`domain` varchar(255) NOT NULL default '',
`action` varchar(255) NOT NULL default '',
@@ -424,8 +427,8 @@
`maildir` varchar(255) NOT NULL default '',
`quota` bigint(20) NOT NULL default '0',
`domain` varchar(255) NOT NULL default '',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
- `modified` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
+ `modified` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`username`)
) {MYISAM} COMMENT='Postfix Admin - Virtual Mailboxes';";
@@ -437,7 +440,7 @@
body text NOT NULL,
cache text NOT NULL,
domain varchar(255) NOT NULL ,
- created datetime NOT NULL default '0000-00-00 00:00:00',
+ created {DATETIME},
active tinyint(4) NOT NULL default '1',
PRIMARY KEY (email),
KEY email (email)
@@ -596,22 +599,22 @@
$table_vacation = table_by_key ('vacation');
if(!_mysql_field_exists($table_admin, 'created')) {
- db_query_parsed("ALTER TABLE $table_admin {RENAME_COLUMN} create_date created DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL;");
+ db_query_parsed("ALTER TABLE $table_admin {RENAME_COLUMN} create_date created {DATETIME};");
}
if(!_mysql_field_exists($table_admin, 'modified')) {
- db_query_parsed("ALTER TABLE $table_admin {RENAME_COLUMN} change_date modified DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL;");
+ db_query_parsed("ALTER TABLE $table_admin {RENAME_COLUMN} change_date modified {DATETIME};");
}
if(!_mysql_field_exists($table_alias, 'created')) {
- db_query_parsed("ALTER TABLE $table_alias {RENAME_COLUMN} create_date created DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL;");
+ db_query_parsed("ALTER TABLE $table_alias {RENAME_COLUMN} create_date created {DATETIME};");
}
if(!_mysql_field_exists($table_alias, 'modified')) {
- db_query_parsed("ALTER TABLE $table_alias {RENAME_COLUMN} change_date modified DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL;");
+ db_query_parsed("ALTER TABLE $table_alias {RENAME_COLUMN} change_date modified {DATETIME};");
}
if(!_mysql_field_exists($table_domain, 'created')) {
- db_query_parsed("ALTER TABLE $table_domain {RENAME_COLUMN} create_date created DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL;");
+ db_query_parsed("ALTER TABLE $table_domain {RENAME_COLUMN} create_date created {DATETIME};");
}
if(!_mysql_field_exists($table_domain, 'modified')) {
- db_query_parsed("ALTER TABLE $table_domain {RENAME_COLUMN} change_date modified DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL;");
+ db_query_parsed("ALTER TABLE $table_domain {RENAME_COLUMN} change_date modified {DATETIME};");
}
if(!_mysql_field_exists($table_domain, 'aliases')) {
db_query_parsed("ALTER TABLE $table_domain ADD COLUMN aliases INT(10) DEFAULT '-1' NOT NULL AFTER description;");
@@ -629,10 +632,10 @@
db_query_parsed("ALTER TABLE $table_domain ADD COLUMN backupmx TINYINT(1) DEFAULT '0' NOT NULL AFTER transport;");
}
if(!_mysql_field_exists($table_mailbox, 'created')) {
- db_query_parsed("ALTER TABLE $table_mailbox {RENAME_COLUMN} create_date created DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL;");
+ db_query_parsed("ALTER TABLE $table_mailbox {RENAME_COLUMN} create_date created {DATETIME};");
}
if(!_mysql_field_exists($table_mailbox, 'modified')) {
- db_query_parsed("ALTER TABLE $table_mailbox {RENAME_COLUMN} change_date modified DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL;");
+ db_query_parsed("ALTER TABLE $table_mailbox {RENAME_COLUMN} change_date modified {DATETIME};");
}
if(!_mysql_field_exists($table_mailbox, 'quota')) {
db_query_parsed("ALTER TABLE $table_mailbox ADD COLUMN quota INT(10) DEFAULT '-1' NOT NULL AFTER maildir;");
@@ -641,7 +644,7 @@
db_query_parsed("ALTER TABLE $table_vacation ADD COLUMN domain VARCHAR(255) DEFAULT '' NOT NULL AFTER cache;");
}
if(!_mysql_field_exists($table_vacation, 'created')) {
- db_query_parsed("ALTER TABLE $table_vacation ADD COLUMN created DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL AFTER domain;");
+ db_query_parsed("ALTER TABLE $table_vacation ADD COLUMN created {DATETIME} AFTER domain;");
}
if(!_mysql_field_exists($table_vacation, 'active')) {
db_query_parsed("ALTER TABLE $table_vacation ADD COLUMN active TINYINT(1) DEFAULT '1' NOT NULL AFTER created;");
@@ -763,8 +766,8 @@
CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('admin') . "` (
`username` varchar(255) NOT NULL default '',
`password` varchar(255) NOT NULL default '',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
- `modified` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
+ `modified` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`username`),
KEY username (`username`)
@@ -775,8 +778,8 @@
`address` varchar(255) NOT NULL default '',
`goto` text NOT NULL,
`domain` varchar(255) NOT NULL default '',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
- `modified` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
+ `modified` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`address`),
KEY address (`address`)
@@ -793,8 +796,8 @@
`quota` int(10) NOT NULL default '0',
`transport` varchar(255) default NULL,
`backupmx` tinyint(1) NOT NULL default '0',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
- `modified` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
+ `modified` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`domain`),
KEY domain (`domain`)
@@ -805,7 +808,7 @@
CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('domain_admins') . "` (
`username` varchar(255) NOT NULL default '',
`domain` varchar(255) NOT NULL default '',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
KEY username (`username`)
) {MYISAM} DEFAULT {LATIN1} COMMENT='Postfix Admin - Domain Admins';
@@ -813,7 +816,7 @@
$result = db_query_parsed("
CREATE TABLE {IF_NOT_EXISTS} `" . table_by_key('log') . "` (
- `timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
+ `timestamp` {DATETIME},
`username` varchar(255) NOT NULL default '',
`domain` varchar(255) NOT NULL default '',
`action` varchar(255) NOT NULL default '',
@@ -830,8 +833,8 @@
`maildir` varchar(255) NOT NULL default '',
`quota` int(10) NOT NULL default '0',
`domain` varchar(255) NOT NULL default '',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
- `modified` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
+ `modified` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`username`),
KEY username (`username`)
@@ -845,7 +848,7 @@
`body` text NOT NULL,
`cache` text NOT NULL,
`domain` varchar(255) NOT NULL,
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`email`),
KEY email (`email`)
@@ -1022,8 +1025,8 @@
CREATE TABLE IF NOT EXISTS $table_alias_domain (
`alias_domain` varchar(255) NOT NULL default '',
`target_domain` varchar(255) NOT NULL default '',
- `created` datetime NOT NULL default '0000-00-00 00:00:00',
- `modified` datetime NOT NULL default '0000-00-00 00:00:00',
+ `created` {DATETIME},
+ `modified` {DATETIME},
`active` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`alias_domain`),
KEY `active` (`active`),
@@ -1626,6 +1629,24 @@
}
+
+function upgrade_1835_mysql() {
+ # change default values for existing datetime fields with a 0000-00-00 default to {DATETIME}
+
+ foreach (array('admin', 'alias', 'alias_domain', 'domain', 'mailbox', 'domain_admins', 'vacation') as $table_to_change) {
+ $table = table_by_key($table_to_change);
+ db_query_parsed("ALTER TABLE `$table` CHANGE `created` `created` {DATETIME}");
+ }
+
+ foreach (array('admin', 'alias', 'alias_domain', 'domain', 'mailbox') as $table_to_change) {
+ $table = table_by_key($table_to_change);
+ db_query_parsed("ALTER TABLE `$table` CHANGE `modified` `modified` {DATETIME}");
+ }
+
+ $table = table_by_key('log');
+ db_query_parsed("ALTER TABLE `$table` CHANGE `timestamp` `timestamp` {DATETIME}");
+}
+
# TODO MySQL:
# - various varchar fields do not have a default value
# https://sourceforge.net/projects/postfixadmin/forums/forum/676076/topic/3419725
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2016-11-01 20:31:54
|
Revision: 1881
http://sourceforge.net/p/postfixadmin/code/1881
Author: christian_boltz
Date: 2016-11-01 20:31:52 +0000 (Tue, 01 Nov 2016)
Log Message:
-----------
upgrade_1835_mysql: fix defaults for both date fields at once
Doing it in two steps fails, see comment by Gabor 'Morc' KORMOS on
https://sourceforge.net/p/postfixadmin/bugs/5/
Note: This is an exception from the "never change an existing
upgrade_*() function" rule because
a) the result doesn't change for people where it worked and
b) it will continue here anyway for people who had upgrade problems
Modified Paths:
--------------
trunk/upgrade.php
Modified: trunk/upgrade.php
===================================================================
--- trunk/upgrade.php 2016-11-01 19:31:41 UTC (rev 1880)
+++ trunk/upgrade.php 2016-11-01 20:31:52 UTC (rev 1881)
@@ -1619,14 +1619,14 @@
function upgrade_1835_mysql() {
# change default values for existing datetime fields with a 0000-00-00 default to {DATETIME}
- foreach (array('admin', 'alias', 'alias_domain', 'domain', 'mailbox', 'domain_admins', 'vacation') as $table_to_change) {
+ foreach (array('domain_admins', 'vacation') as $table_to_change) {
$table = table_by_key($table_to_change);
db_query_parsed("ALTER TABLE `$table` CHANGE `created` `created` {DATETIME}");
}
foreach (array('admin', 'alias', 'alias_domain', 'domain', 'mailbox') as $table_to_change) {
$table = table_by_key($table_to_change);
- db_query_parsed("ALTER TABLE `$table` CHANGE `modified` `modified` {DATETIME}");
+ db_query_parsed("ALTER TABLE `$table` CHANGE `created` `created` {DATETIME}, CHANGE `modified` `modified` {DATETIME}");
}
$table = table_by_key('log');
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|