Permalink
Browse files

Upgrade SQlite db to v1837

Includes a TODO for v1836. Not sure if it's needed... Haven't ran into
any issues yet.
  • Loading branch information...
evaryont committed Oct 6, 2017
1 parent c5136c4 commit f568309ef5f566760d36ce40f88f61c94e977946
Showing with 31 additions and 0 deletions.
  1. +31 −0 upgrade.php
View
@@ -63,6 +63,17 @@ function _mysql_field_exists($table, $field) {
return false;
}
function _sqlite_field_exists($table, $field) {
$sql = "PRAGMA table_info($table)";
$r = db_query($sql);
while($row = db_row($r['result'])) {
if ($row[1] == $field) {
return true;
}
}
return false;
}
function _db_field_exists($table, $field) {
global $CONF;
if($CONF['database_type'] == 'pgsql') {
@@ -1693,3 +1704,23 @@ function upgrade_1837_mysql() {
# including vacation.modified - should be {DATE}, not {DATECURRENT}
# https://sourceforge.net/tracker/?func=detail&aid=1699218&group_id=191583&atid=937964
# @todo vacation.email has 2 indizes
# Upgrading to v1835 & v1836 in sqlite have a couple of peculiarities:
# - DATE and DATETIME are the same type internally (NUMERIC)
# - SQLite does not support ALTER COLUMN. At all.
# TODO: Rename/create anew/migrate/drop tables for v1836... If it matters?
function upgrade_1837_sqlite() {
# Add columns for the alternative contact to reset a forgotten password.
foreach(array('admin', 'mailbox') as $table_to_change) {
$table = table_by_key($table_to_change);
if(!_sqlite_field_exists($table, 'phone')) {
db_query_parsed("ALTER TABLE `$table` ADD COLUMN `phone` varchar(30) NOT NULL DEFAULT ''");
}
if(!_sqlite_field_exists($table, 'email_other')) {
db_query_parsed("ALTER TABLE `$table` ADD COLUMN `email_other` varchar(255) NOT NULL DEFAULT ''");
}
}
}

0 comments on commit f568309

Please sign in to comment.