PrivateBin\Data\Database::_upgradeDatabase PHP Метод

_upgradeDatabase() приватный статический Метод

upgrade the database schema from an old version
private static _upgradeDatabase ( string $oldversion ) : void
$oldversion string
Результат void
    private static function _upgradeDatabase($oldversion)
    {
        $dataType = self::$_type === 'pgsql' ? 'TEXT' : 'BLOB';
        switch ($oldversion) {
            case '0.21':
                // create the meta column if necessary (pre 0.21 change)
                try {
                    self::$_db->exec('SELECT meta FROM ' . self::_sanitizeIdentifier('paste') . ' LIMIT 1;');
                } catch (PDOException $e) {
                    self::$_db->exec('ALTER TABLE ' . self::_sanitizeIdentifier('paste') . ' ADD COLUMN meta TEXT;');
                }
                // SQLite only allows one ALTER statement at a time...
                self::$_db->exec('ALTER TABLE ' . self::_sanitizeIdentifier('paste') . ' ADD COLUMN attachment ' . (self::$_type === 'pgsql' ? 'TEXT' : 'MEDIUMBLOB') . ';');
                self::$_db->exec('ALTER TABLE ' . self::_sanitizeIdentifier('paste') . " ADD COLUMN attachmentname {$dataType};");
                // SQLite doesn't support MODIFY, but it allows TEXT of similar
                // size as BLOB, so there is no need to change it there
                if (self::$_type !== 'sqlite') {
                    self::$_db->exec('ALTER TABLE ' . self::_sanitizeIdentifier('paste') . ' ADD PRIMARY KEY (dataid), MODIFY COLUMN data $dataType;');
                    self::$_db->exec('ALTER TABLE ' . self::_sanitizeIdentifier('comment') . " ADD PRIMARY KEY (dataid), MODIFY COLUMN data {$dataType}, " . "MODIFY COLUMN nickname {$dataType}, MODIFY COLUMN vizhash {$dataType};");
                } else {
                    self::$_db->exec('CREATE UNIQUE INDEX IF NOT EXISTS paste_dataid ON ' . self::_sanitizeIdentifier('paste') . '(dataid);');
                    self::$_db->exec('CREATE UNIQUE INDEX IF NOT EXISTS comment_dataid ON ' . self::_sanitizeIdentifier('comment') . '(dataid);');
                }
                self::$_db->exec('CREATE INDEX IF NOT EXISTS comment_parent ON ' . self::_sanitizeIdentifier('comment') . '(pasteid);');
                // no break, continue with updates for 0.22
            // no break, continue with updates for 0.22
            case '0.22':
                self::_exec('UPDATE ' . self::_sanitizeIdentifier('config') . ' SET value = ? WHERE id = ?', array('1.0', 'VERSION'));
        }
    }