From d04c82fbcb78196ab8b9ce1a850eea98076df3c3 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sat, 30 Dec 2017 12:39:09 +0100 Subject: [PATCH] change default for vacation.activeuntil to 2038 When adding the activeuntil field during the upgrade, it got set to 2000-01-01 which is a bad idea for existing vacation entries - the new vacation.pl will consider them as outdated. Introduce a new {DATEFUTURE}, and set the default value for activeuntil to 2038 (that's the limit in MySQL for 'timestamp' columns, we'll have to switch to 'datetime' in 20 years ;-) Note that sqlite doesn't support changing the field default, so sqlite users will have to live with the wrong default. Also note that this fix does not change existing vacation entries if you already have the activeuntil column. Reported by Christoph Lechleitner on the mailinglist --- upgrade.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/upgrade.php b/upgrade.php index 323a8cba..b01229f8 100644 --- a/upgrade.php +++ b/upgrade.php @@ -250,6 +250,7 @@ function db_query_parsed($sql, $ignore_errors = 0, $attach_mysql = "") { '{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 ... + '{DATEFUTURE}' => "timestamp NOT NULL default '2038-01-19'", # different default timestamp for vacation.activeuntil '{DATECURRENT}' => 'timestamp NOT NULL default CURRENT_TIMESTAMP', # only allowed once per table in MySQL ); $sql = "$sql $attach_mysql"; @@ -272,6 +273,7 @@ function db_query_parsed($sql, $ignore_errors = 0, $attach_mysql = "") { '{BIGINT}' => 'bigint(20) NOT NULL DEFAULT 0', '{DATETIME}' => "datetime NOT NULL default '2000-01-01'", '{DATE}' => "datetime NOT NULL default '2000-01-01'", + '{DATEFUTURE}' => "datetime NOT NULL default '2038-01-19'", # different default timestamp for vacation.activeuntil '{DATECURRENT}' => 'datetime NOT NULL default CURRENT_TIMESTAMP', ); } elseif($CONF['database_type'] == 'pgsql') { @@ -295,6 +297,7 @@ function db_query_parsed($sql, $ignore_errors = 0, $attach_mysql = "") { '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 + '{DATEFUTURE}' => "timestamp with time zone default '2038-01-19'", # stay in sync with MySQL '{DATECURRENT}' => 'timestamp with time zone default now()', ); @@ -1383,7 +1386,7 @@ function upgrade_945_mysql_pgsql() { function upgrade_946_mysql_pgsql() { # taken from upgrade_727_mysql, needs to be done for all databases _db_add_field('vacation', 'activefrom', '{DATE}', 'body'); - _db_add_field('vacation', 'activeuntil', '{DATE}', 'activefrom'); + _db_add_field('vacation', 'activeuntil', '{DATEFUTURE}', 'activefrom'); } function upgrade_968_pgsql() { # pgsql counterpart for upgrade_169_mysql() - allow really big quota @@ -1629,7 +1632,7 @@ function upgrade_1824_sqlite() { `subject` varchar(255) NOT NULL, `body` {FULLTEXT} NOT NULL, `activefrom` {DATE}, - `activeuntil` {DATE}, + `activeuntil` {DATEFUTURE}, `cache` {FULLTEXT} NOT NULL DEFAULT '', `domain` varchar(255) NOT NULL, `interval_time` {INT}, @@ -1727,3 +1730,9 @@ function upgrade_1837_sqlite() { function upgrade_1839() { _db_add_field('log', 'id', '{AUTOINCREMENT} {PRIMARY}' , 'data'); } + +function upgrade_1840_mysql_pgsql() { + # sqlite doesn't support changing the default value + $vacation = table_by_key('vacation'); + db_query_parsed("ALTER TABLE $vacation ALTER COLUMN activeuntil SET DEFAULT '2038-01-19'"); +}