Merge pull request #1343 from PrivateBin/db-version-upgrade

refactor database schema upgrade to support skipping versions
This commit is contained in:
El RIDO 2024-05-26 08:40:29 +02:00 committed by GitHub
commit f313578892
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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,13 +929,11 @@ 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" = ?',
array(Controller::VERSION, 'VERSION') array(Controller::VERSION, 'VERSION')
); );
} }
}
} }