refactor database schema upgrade to support skipping versions

This commit is contained in:
El RIDO 2024-05-25 09:40:41 +02:00
parent b96c8ae531
commit 99a3e087ed

View File

@ -853,8 +853,7 @@ class Database extends AbstractData
{ {
$dataType = $this->_getDataType(); $dataType = $this->_getDataType();
$attachmentType = $this->_getAttachmentType(); $attachmentType = $this->_getAttachmentType();
switch ($oldversion) { if (version_compare($oldversion, '0.21', '<=')) {
case '0.21':
// create the meta column if necessary (pre 0.21 change) // create the meta column if necessary (pre 0.21 change)
try { try {
$this->_db->exec( $this->_db->exec(
@ -902,8 +901,8 @@ class Database extends AbstractData
$this->_sanitizeIdentifier('comment_parent') . '" ON "' . $this->_sanitizeIdentifier('comment_parent') . '" ON "' .
$this->_sanitizeIdentifier('comment') . '" ("pasteid")' $this->_sanitizeIdentifier('comment') . '" ("pasteid")'
); );
// no break, continue with updates for 0.22 and later }
case '1.3': if (version_compare($oldversion, '1.3', '<=')) {
// SQLite doesn't support MODIFY, but it allows TEXT of similar // SQLite doesn't support MODIFY, but it allows TEXT of similar
// size as BLOB and PostgreSQL uses TEXT, so there is no need // size as BLOB and PostgreSQL uses TEXT, so there is no need
// to change it there // to change it there
@ -913,8 +912,8 @@ class Database extends AbstractData
"\" MODIFY COLUMN \"data\" $attachmentType" "\" MODIFY COLUMN \"data\" $attachmentType"
); );
} }
// no break, continue with updates for all newer versions }
case '1.7.2': if (version_compare($oldversion, '1.7.1', '<=')) {
$supportsDropColumn = true; $supportsDropColumn = true;
if ($this->_type === 'sqlite') { if ($this->_type === 'sqlite') {
try { try {
@ -930,8 +929,7 @@ class Database extends AbstractData
'" DROP COLUMN "postdate"' '" DROP COLUMN "postdate"'
); );
} }
// no break, continue with updates for all newer versions }
default:
$this->_exec( $this->_exec(
'UPDATE "' . $this->_sanitizeIdentifier('config') . 'UPDATE "' . $this->_sanitizeIdentifier('config') .
'" SET "value" = ? WHERE "id" = ?', '" SET "value" = ? WHERE "id" = ?',
@ -939,4 +937,3 @@ class Database extends AbstractData
); );
} }
} }
}