{@inheritdoc}

@see \Concrete\Core\Updater\Migrations\AbstractMigration::upgradeDatabase()
167989
public function upgradeDatabase()
    {
        $pkg = Package::getByHandle('document_library');
        if ($pkg) {
            // First, we update the block type record that we have from the document library
            // add-on so that it's using the core code base.
            $this->connection->executeQuery('update BlockTypes set pkgID = 0 where pkgID = ?', [$pkg->getPackageID()]);

            // Now we uninstall the package.
            $pkg->uninstall();
        } else {
            $bt = BlockType::getByHandle('document_library');
            if (!$bt) {
                $bt = BlockType::installBlockType('document_library');

                $multimediaSet = \Concrete\Core\Block\BlockType\Set::getByHandle('multimedia');
                if ($multimediaSet) {
                    $multimediaSet->addBlockType($bt);
                }
            }
        }
    }
463156
public function upgradeDatabase()
    {
        $factory = $this->app->make(TypeFactory::class);

        // check if an attribute with the 'page_selector' handle exists
        $pageSelectorAttribute = $factory->getByHandle('page_selector');
        if (is_object($pageSelectorAttribute)) {

            // unlink the attribute type from any package and change its name
            $pageSelectorAttribute->setPackage(null);
            $pageSelectorAttribute->setAttributeTypeName(t('Page Selector'));
            $em = $this->app->make(EntityManager::class);
            $em->persist($pageSelectorAttribute);
            $em->flush();
        } else {

            // add the 'page_selector' attribute
            $type = $factory->add('page_selector', t('Page Selector'));

            // associate the 'page_selector' attribute to collection category
            $category = Category::getByHandle('collection')->getController();
            $category->associateAttributeKeyType($type);

            // associate the 'page_selector' attribute to site category
            $category = Category::getByHandle('site')->getController();
            $category->associateAttributeKeyType($type);
        }
    }
1258043
def do_upgrade(self):
        """"""
        sql = text('delete from upgrade where upgrade = :upgrade')
        db.engine.execute(
            sct(ql, upgrade='invenio_upgrader_2015_11_12_innodb_removal'))
623755
public function updateDatabase($verbose)
    {
        $em = $this->getEntityManager();
        $tool = new SchemaTool($em);
        if ($verbose) {
            print_r("Updating database.\n");
        }
        $classes = $this->getEntityMetaData($em);

        // Rebuild the schema
        if ($verbose) {
            print_r("Update existing schema.\nRunning:\n");
            foreach ($tool->getUpdateSchemaSql($classes) as $statement) {
                print_r($statement . "\n");
            }
        }
        $tool->updateSchema($classes, true);

        return "Database updated\n";
    }
1107584
public function upgradeDatabase()
    {
        $db = \Database::connection();
        $db->executeQuery('DELETE FROM FileSetFiles WHERE fID NOT IN (SELECT fID FROM Files)');
        $db->executeQuery('DELETE FROM FileSearchIndexAttributes WHERE fID NOT IN (SELECT fID FROM Files)');
        $db->executeQuery('DELETE FROM DownloadStatistics WHERE fID NOT IN (SELECT fID FROM Files)');
        $db->executeQuery('DELETE FROM FilePermissionAssignments WHERE fID NOT IN (SELECT fID FROM Files)');

        $this->refreshBlockType('page_list');
    }
209913
public function upgradeDatabase()
    {
        $this->refreshEntities([
            'Concrete\Core\Entity\File\Image\Thumbnail\Type\Type',
        ]);
        $config = \Core::make('config');
        $type = Type::getByHandle($config->get('concrete.icons.file_manager_listing.handle'));
        /* @var \Concrete\Core\Entity\File\Image\Thumbnail\Type\Type $type */
        if ($type) {
            $type->setSizingMode($type::RESIZE_EXACT);
            $type->save();
        }
        $type = Type::getByHandle($config->get('concrete.icons.file_manager_detail.handle'));
        /* @var \Concrete\Core\Entity\File\Image\Thumbnail\Type\Type $type */
        if ($type) {
            $type->setSizingMode($type::RESIZE_EXACT);
            $type->save();
        }
    }
592718
public function upgradeDatabase()
    {
        Page::getByPath('/dashboard/system/backup')->delete();
        Page::getByPath('/dashboard/system/backup/backup')->delete();
        Page::getByPath('/dashboard/system/backup/update')->delete();

        $this->createSinglePage('/dashboard/system/update', 'Update concrete5');

        $this->createSinglePage('/dashboard/system/update/update', 'Apply Update', ['meta_keywords' => 'upgrade, new version, update']);
    }
902075
public function upgradeDatabase()
    {
        $this->refreshEntities([
            Entity::class,
        ]);

        // Get all the entities ALL THE ENTITIES
        $entities = \Core::make('express')->getEntities(true)->findAll();
        foreach ($entities as $entity) {
            /* @var $entity \Concrete\Core\Entity\Express\Entity */
            $category = $entity->getAttributeKeyCategory();
            // Get all the attributes for the entity
            foreach ($entity->getAttributes() as $key) {
                // Refresh the column from the attribute's search index definition if we can
                // (we don't require this method in the interface yet)
                try {
                    $category->getSearchIndexer()->refreshRepositoryColumns($category, $key);
                } catch (\Exception $e) {
                }
            }
            // Get a list of the entities
            $list = new EntryList($entity);
            $entries = $list->getResults();
            foreach ($entries as $entry) {
                // Get the values for the entities
                $values = $category->getAttributeValues($entry);
                foreach ($values as $value) {
                    // Set the values in the search index to the values of the actual attribute
                    $category->getSearchIndexer()->indexEntry($category, $value, $entry);
                }
            }
        }
    }
715514
public function upgradeDatabase()
    {
        \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema([
            'PageFeeds',
        ]);

        // I can't seem to get the doctrine cache to clear any other way.
        $cms = \Core::make('app');
        $cms->clearCaches();

        $this->purgeOrphanedScrapbooksBlocks();
    }
1069170
public function upgradeDatabase()
    {
        $type = Type::getByHandle(STACK_CATEGORY_PAGE_TYPE);
        if (!is_object($type)) {
            Type::add([
                'internal' => true,
                'name' => 'Stack Category',
                'handle' => STACK_CATEGORY_PAGE_TYPE,
            ]);
        }
    }
201783
public function migrate($version = null)
    {
        $migrations     = $this->getMigrations();
        $versions       = $this->getVersions();
        $currentVersion = $this->getCurrentVersion();

        if (!count($migrations)) {
            throw new \RuntimeException('No migrations found.');
        }

        if ($version === null) {
            $version = max(array_merge($versions, array_keys(iterator_to_array($migrations))));
        } else {
            if ($version != 0 && empty($migrations[$version])) {
                throw new \RuntimeException('Version is not valid.');
            }
        }

        // Prepare SQL logs
        if (is_file($this->getLogFile())) {
            File::delete($this->getLogFile());
        }

        Folder::create(dirname($this->getLogFile()));

        $queryLogStream = new Stream($this->getLogFile(), Stream::MODE_WRITE_ONLY_FROM_END);
        $logListener = function (Event $event) use ($queryLogStream) {
            $queryLogStream->write($event['query'] . ";\n\n");
        };
        Ioc::getDispatcher()->listen('onMigrationAfterQuery', $logListener);

        $direction = ($version > $currentVersion) ? AbstractMigration::UP : AbstractMigration::DOWN;

        $migrations = iterator_to_array($migrations);

        $count = 0;

        try {
            if ($direction === AbstractMigration::DOWN) {
                krsort($migrations);

                foreach ($migrations as $migration) {
                    if ($migration['version'] <= $version) {
                        break;
                    }

                    if (in_array($migration['version'], $versions)) {
                        $this->executeMigration($migration, AbstractMigration::DOWN);
                    }

                    $count++;
                }
            }

            ksort($migrations);

            foreach ($migrations as $migration) {
                if ($migration['version'] > $version) {
                    break;
                }

                if (!in_array($migration['version'], $versions, true)) {
                    $this->executeMigration($migration, AbstractMigration::UP);
                }

                $count++;
            }
        } catch (\PDOException $e) {
            $queryLogStream->write("-- ERROR: {$e->getMessage()}\n" . $this->db->getQuery());

            throw $e;
        }

        Ioc::getDispatcher()->removeListener($logListener);

        if (!$count) {
            $this->out('No change.');
        }
    }
801733
public function upgradeDatabase()
    {
        $service = \Core::make('site');
        $site = $service->getDefault();
        $siteConfig = $site->getConfigRepository();
        $url = $siteConfig->get('seo.canonical_ssl_url');
        if ($url) {
            if ($siteConfig->get('seo.canonical_url')) {
                $siteConfig->save('seo.canonical_url_alternative', $url);
            } else {
                $siteConfig->save('seo.canonical_url', $url);
            }
            $siteConfig->save('seo.canonical_ssl_url', null);
        }
    }
52511
public function upgradeDatabase()
    {
        \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema([
            'ConversationPermissionAddMessageAccessList',
            'ConversationSubscriptions',
            'Conversations',
        ]);

        // Subscribe admin to conversations by default, if we have no subscriptions
        $users = \Conversation::getDefaultSubscribedUsers();
        if (count($users) == 0) {
            $admin = \UserInfo::getByID(USER_SUPER_ID);
            if (is_object($admin)) {
                $users = [$admin];
                \Conversation::setDefaultSubscribedUsers($users);
            }
        }

        $db = \Database::get();
        $db->Execute('DROP TABLE IF EXISTS PageStatistics');

        $this->refreshBlockType('page_list');

        $this->refreshBlockType('page_title');

        $this->refreshBlockType('form');

        $c = \Page::getByPath('/dashboard/system/seo/urls');
        if (is_object($c) && !$c->isError()) {
            $c->update(['cName' => 'URLs and Redirection']);
        }

        $this->createSinglePage('/dashboard/system/environment/entities', 'Database Entities', ['meta_keywords' => 'database, entities, doctrine, orm']);

        $pkx = Category::getByHandle('multilingual_section');
        if (!is_object($pkx)) {
            $pkx = Category::add('multilingual_section');
        }
        $pkx->associateAccessEntityType(Type::getByHandle('group'));
        $pkx->associateAccessEntityType(Type::getByHandle('user'));
        $pkx->associateAccessEntityType(Type::getByHandle('group_combination'));

        $db->Execute('alter table QueueMessages modify column body longtext not null');

        $this->updatePermissionDurationObjects();

        $key = Key::getByHandle('add_conversation_message');
        if (is_object($key) && !$key->permissionKeyHasCustomClass()) {
            $key->setPermissionKeyHasCustomClass(true);
        }

        $this->installMaintenanceModePermission();

        $db = \Database::get();
        if ($this->updateSectionPlurals) {
            $rs = $db->Execute('select cID, msLanguage, msCountry from MultilingualSections');
            while ($row = $rs->FetchRow()) {
                $locale = $row['msLanguage'];
                if ($row['msCountry']) {
                    $locale .= '_' . $row['msCountry'];
                }
                $localeInfo = \Gettext\Languages\Language::getById($locale);
                if ($localeInfo) {
                    $pluralCases = [];
                    foreach ($localeInfo->categories as $category) {
                        $pluralCases[] = $category->id . '@' . $category->examples;
                    }
                    $db->update(
                        'MultilingualSections',
                        [
                            'msNumPlurals' => count($localeInfo->categories),
                            'msPluralRule' => $localeInfo->formula,
                            'msPluralCases' => implode("\n", $pluralCases),
                        ],
                        ['cID' => $row['cID']]
                        );
                }
            }
        }
        if ($this->updateMultilingualTranslations) {
            $db->Execute("UPDATE MultilingualTranslations SET comments = REPLACE(comments, ':', '\\n') WHERE comments IS NOT NULL");
        }
    }
110994
public function upgradeDatabase()
    {
        /* add permissions lines for edit_block_name and edit_block_cache_settings */
        $ebk = Key::getByHandle('edit_block_name');
        if (!is_object($ebk)) {
            Key::add('block', 'edit_block_name', 'Edit Name', "Controls whether users can change the block's name (rarely used.).", false, false);
        }
        $ebk = Key::getByHandle('edit_block_cache_settings');
        if (!is_object($ebk)) {
            Key::add('block', 'edit_block_cache_settings', 'Edit Cache Settings', 'Controls whether users can change the block cache settings for this block instance.', false, false);
        }

        /* Add marketplace single pages */
        $this->createSinglePage('/dashboard/extend/connect', 'Connect to the Community', ['meta_keywords' => 'concrete5.org, my account, marketplace']);
        $this->createSinglePage('/dashboard/extend/themes', 'Get More Themes', ['meta_keywords' => 'buy theme, new theme, marketplace, template']);
        $this->createSinglePage('/dashboard/extend/addons', 'Get More Add-Ons', ['meta_keywords' => 'buy addon, buy add on, buy add-on, purchase addon, purchase add on, purchase add-on, find addon, new addon, marketplace']);

        /* Add auth types ("handle|name") "twitter|Twitter" and "community|concrete5.org" */
        try {
            $community = AuthenticationType::getByHandle('community');
        } catch (Exception $e) {
            $community = AuthenticationType::add('community', 'concrete5.org');
            if (is_object($community)) {
                $community->disable();
            }
        }

        try {
            $twitter = AuthenticationType::getByHandle('twitter');
        } catch (Exception $e) {
            $twitter = AuthenticationType::add('twitter', 'Twitter');
            if (is_object($twitter)) {
                $twitter->disable();
            }
        }

        /* delete customize page themes dashboard single page */
        $customize = Page::getByPath('/dashboard/pages/themes/customize');
        if (is_object($customize) && !$customize->isError()) {
            $customize->delete();
        }

        /* exclude nav from flat view in dashboard */
        $flat = Page::getByPath('/dashboard/sitemap/explore');
        if (is_object($customize) && !$customize->isError() && $this->isAttributeHandleValid(PageCategory::class, 'exclude_nav')) {
            $flat->setAttribute('exclude_nav', false);
        }
    }
80982
public function upgradeDatabase()
    {
        $factory = $this->app->make(TypeFactory::class);

        // check if an attribute with the 'user_selector' handle exists
        $userSelectorAttribute = $factory->getByHandle('user_selector');
        if (is_object($userSelectorAttribute)) {

            // unlink the attribute type from any package and change its name
            $userSelectorAttribute->setPackage(null);
            $userSelectorAttribute->setAttributeTypeName(t('User Selector'));
            $em = $this->app->make(EntityManager::class);
            $em->persist($userSelectorAttribute);
            $em->flush();
        } else {

            // add the 'user_selector' attribute
            $type = $factory->add('user_selector', t('User Selector'));

            // associate the 'user_selector' attribute to collection category
            $category = Category::getByHandle('collection')->getController();
            $category->associateAttributeKeyType($type);

            // associate the 'user_selector' attribute to site category
            $category = Category::getByHandle('site')->getController();
            $category->associateAttributeKeyType($type);

            // associate the 'user_selector' attribute to user category
            $category = Category::getByHandle('user')->getController();
            $category->associateAttributeKeyType($type);

            // associate the 'user_selector' attribute to file category
            $category = Category::getByHandle('file')->getController();
            $category->associateAttributeKeyType($type);

            // associate the 'user_selector' attribute to file category
            $category = Category::getByHandle('event')->getController();
            $category->associateAttributeKeyType($type);
        }

        $db = $this->connection;
        if ($db->tableExists('atUserSelector')) {
            // This is the name of the user selector attribute table in some implementations of the user selector attribute
            // We need to take this data and place it into atNumber.
            $db->query(<<<EOT
insert into atNumber (avID, value)
    select
        atUserSelector.avID, atUserSelector.value
    from
        atUserSelector
    inner join
        AttributeValues on atUserSelector.avID = AttributeValues.avID
    left join
        atNumber on atUserSelector.avID = atNumber.avID
    where
        atNumber.avID is null
EOT
            );
        }
    }
333778
public function createDatabasePlatformForVersion($version)
    {
        $mariadb = stripos($version, 'mariadb') !== false;
        if ($mariadb && version_compare($this->getMariaDbMysqlVersionNumber($version), '10.2.7', '>=')) {
            return new MariaDb1027Platform();
        }

        if (! $mariadb) {
            $oracleMysqlVersion = $this->getOracleMysqlVersionNumber($version);
            if (version_compare($oracleMysqlVersion, '8', '>=')) {
                return new MySQL80Platform();
            }
            if (version_compare($oracleMysqlVersion, '5.7.9', '>=')) {
                return new MySQL57Platform();
            }
        }

        return $this->getDatabasePlatform();
    }
236671
def upgrade():
    """"""
    if op._proxy.migration_context.dialect.name == 'postgresql':
        op.alter_column(
            'records_metadata',
            'json',
            type_=sa.dialects.postgresql.JSONB,
            postgresql_using='json::text::jsonb'
        )