{@inheritdoc}

@see \Concrete\Core\Updater\Migrations\AbstractMigration::upgradeDatabase()
778686
public function upgradeDatabase()
    {
        $this->refreshEntities([
            'Concrete\Core\Entity\Attribute\Key\Settings\BooleanSettings',
        ]);
        $em = $this->connection->getEntityManager();
        $ak = CollectionKey::getByHandle('exclude_nav');
        if ($ak) {
            $settings = $ak->getController()->getAttributeKeySettings();
            if ($settings) {
                $settings->setCheckboxLabel('Exclude Page from Navigation');
                $settings->setAttributeKey($ak);
                $em->persist($settings);
            }
        }
        $ak = CollectionKey::getByHandle('exclude_page_list');
        if ($ak) {
            $settings = $ak->getController()->getAttributeKeySettings();
            if ($settings) {
                $settings->setCheckboxLabel('Exclude Page from Page List Blocks');
                $settings->setAttributeKey($ak);
                $em->persist($settings);
            }
        }
        $ak = CollectionKey::getByHandle('is_featured');
        if ($ak) {
            $settings = $ak->getController()->getAttributeKeySettings();
            if ($settings) {
                $settings->setCheckboxLabel('Feature this Page');
                $settings->setAttributeKey($ak);
                $em->persist($settings);
            }
        }
        $em->flush();
    }
218971
public function upgradeDatabase()
    {
        $app = Application::getFacadeApplication();

        $this->refreshEntities([
            DateTimeSettings::class,
        ]);
        $config = $app->make('config');
        if (!$config->get('app.curl.verifyPeer')) {
            $config->save('app.http_client.sslverifypeer', false);
        }
        $this->migrateDrafts();

        $this->createSinglePage('/dashboard/system/files/thumbnails/options', 'Thumbnail Options', ['exclude_nav' => true, 'meta_keywords' => 'thumbnail, format, png, jpg, jpeg, quality, compression, gd, imagick, imagemagick, transparency']);
    }
1022577
private void upgradeDatabase(KelpUpgrade upgradeKelp)
    throws IOException
  {
    Collections.sort(_tableList, 
                     (x,y)->x.row().name().compareTo(y.row().name()));
    
    for (TableEntry10 table : _tableList) {
      TableUpgrade upgradeTable = upgradeKelp.table(table.key(), table.row());
      
      upgradeTable(table, upgradeTable);
    }
  }
328907
public static function updateDatabase()
    {
        FileSystem::mkDir(DIR_TEMP . 'GeoIPCountryCSV');

        $file_to_extract = DIR_TEMP . 'GeoIPCountryCSV/GeoIPCountryCSV.zip';
        if (!file_exists($file_to_extract) || filemtime($file_to_extract) < NOW - 86400) {
            $f = @file_get_contents('http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip');
            if ($f === false) {
                throw new RuntimeException('Can not connect to MaxMind');
            }

            file_put_contents(DIR_TEMP . 'GeoIPCountryCSV/GeoIPCountryCSV.zip', $f);
            unset($f);
        }


        // Extract file
        $zip = new \ZipArchive;
        $zip->open($file_to_extract);
        $zip->extractTo(DIR_TEMP . 'GeoIPCountryCSV/');
        $zip->close();

        $ranges = new MaxMindGeoIpRangeEntityRepository;
        $countries = new MaxMindGeoIpCountryEntityRepository();

        // Create new tables
        $ranges->ensureDbTableExists();
        $countries->ensureDbTableExists();

        $ranges->deleteObjectCollection();
        $countries->deleteObjectCollection();

        $countries_sql = $ranges_sql = [];
        $fh = fopen(DIR_TEMP . 'GeoIPCountryCSV/GeoIPCountryWhois.csv', 'rb');

        while (($q = fgetcsv($fh, 4096, ',')) !== false) {
            if (!isset($q[4])) {
                continue;
            }

            $ranges_sql[] = '(NULL, "' . sql_prepare($q[4]) . '","' . sql_prepare($q[2]) . '","' . sql_prepare($q[3]) . '")';
            if (!isset($countries_sql[$q[4]])) {
                $countries_sql[$q[4]] = '(NULL, "' . $q[4] . '","' . sql_prepare($q[5]) . '")';
            }
        }
        fclose($fh);

        // Clean SQL works much faster and we now what values are
        q('INSERT INTO `cms_maxmind_geoip_c` VALUES ' . implode(',', $countries_sql), false);

        $q = [];
        $ql = 0;
        $so = count($ranges_sql);

        for ($i = 0; $i < $so; ++$i) {
            $l = strlen($ranges_sql[$i]);
            if ($ql + $l > 983040) {
                q('INSERT INTO `cms_maxmind_geoip_r` VALUES ' . implode(',', $q));
                $q = [];
                $ql = 0;
            }
            $q[] = $ranges_sql[$i];
            $ql += $l;
        }

        // If have anything to save
        if ($q) {
            q('INSERT INTO `cms_maxmind_geoip_r` VALUES ' . implode(',', $q));
        }

        q('OPTIMIZE TABLE `cms_maxmind_geoip_r`,`cms_maxmind_geoip_c`');

        Cacher::getInstance()->getDefaultCacher()->set('geo_ip_lmt', NOW);
    }
1260800
public function upgradeDatabase()
    {
        $all_tables = $this->connection->executeQuery('SHOW TABLES LIKE "%ExpressSearchIndexAttributes"')->fetchAll();
        $all_tables = array_map(function ($row) {
            return array_values($row)[0];
        }, $all_tables);

        $entity_tables = [];

        $entities = \Core::make('express')->getEntities(true)->findAll();
        foreach ($entities as $entity) {
            /* @var $entity \Concrete\Core\Entity\Express\Entity */
            $entity_tables[] = $entity->getAttributeKeyCategory()->getIndexedSearchTable();
        }

        $drop_tables = array_diff($all_tables, $entity_tables);

        foreach ($drop_tables as $table) {
            $this->connection->exec('DROP TABLE IF EXISTS ' . $table);
        }
    }
799854
public function database()
    {
        $databaseManager = new DatabaseManager;
        $response = $databaseManager->migrateAndSeed();

        return redirect()->route('LaravelUpdater::final')
                         ->with(['message' => $response]);
    }
100609
public function upgradeDatabase()
    {
        $app = Facade::getFacadeApplication();
        $categoryService = $app->make(CategoryService::class);
        /* @var CategoryService $categoryService */
        $typeFactory = $app->make(TypeFactory::class);
        /* @var TypeFactory $typeFactory */
        $em = $app->make(EntityManager::class);

        $type = $typeFactory->getByHandle('express');
        if (!$type) {
            $type = $typeFactory->add('express', 'Express Entity');
        }

        foreach (['collection', 'user', 'file', 'site'] as $handle) {
            $category = $categoryService->getByHandle($handle);
            if ($category !== null) {
                $categoryTypes = $category->getAttributeTypes();
                if (!$categoryTypes->contains($type)) {
                    $categoryTypes->add($type);
                }
            }
        }
        $em->flush();
    }
1332788
public static function isCurrentVersionNewerThanDatabaseVersion()
    {
        $app = Application::getFacadeApplication();
        $db = $app->make(Connection::class);
        $config = $app->make('config');
        $database = $db->fetchColumn('select max(version) from SystemDatabaseMigrations');
        $code = $config->get('concrete.version_db');

        return $database < $code;
    }
660599
public function upgradeDatabase()
    {
        /* delete customize page themes dashboard single page */
        $customize = Page::getByPath('/dashboard/pages/themes/customize');
        if (is_object($customize) && !$customize->isError()) {
            $customize->delete();
        }

        /* Add inspect single page back if it's missing */
        $this->createSinglePage('/dashboard/pages/themes/inspect', '', ['meta_keywords' => 'inspect, templates', 'exclude_nav' => 1]);

        $this->createSinglePage('/members/directory', '', ['exclude_nav' => 1]);

        $this->refreshBlockType('feature');

        $this->refreshBlockType('image_slider');

        $db = Database::get();
        $sm = $db->getSchemaManager();
        $schemaTables = $sm->listTableNames();
        if (in_array('signuprequests', $schemaTables)) {
            $db->query('alter table signuprequests rename SignupRequestsTmp');
            $db->query('alter table SignupRequestsTmp rename SignupRequests');
        }
        if (in_array('userbannedips', $schemaTables)) {
            $db->query('alter table userbannedips rename UserBannedIPsTmp');
            $db->query('alter table UserBannedIPsTmp rename UserBannedIPs');
        }

        // Clean up File stupidity
        $r = $db->Execute('select Files.fID from Files left join FileVersions on (Files.fID = FileVersions.fID) where FileVersions.fID is null');
        while ($row = $r->FetchRow()) {
            $db->Execute('delete from Files where fID = ?', [$row['fID']]);
        }
    }
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");
        }
    }
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'
        )
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']);
    }
391438
public function up(Database $db)
    {
        $collection = $db->selectCollection($this->collection);
        $targetCollection = $db->selectCollection('Translation');

        $aggregate = [
            [
                '$match' => [
                    'isLocalized' => true,
                    'locale' => ['$ne' => 'en'],
                    'translated' => ['$ne' => null]
                ]
            ],
            [
                '$group' => [
                    '_id' => ['original' => '$original', 'locale' => '$locale'],
                    'translated' => ['$addToSet' => '$translated'],
                    'count' => ['$sum' => 1]
                ]
            ]
        ];

        foreach ($collection->aggregate($aggregate, ['cursor' => true]) as $translatable) {
            $original = $translatable['_id']['original'];
            $language = $translatable['_id']['locale'];
            $translation = $translatable['translated'][0];

            $rec = [
                'original' => $original,
                'language' => $language,
                'localized' => $translation
            ];

            try {
                $targetCollection->insert($rec);
            } catch (\Exception $e) {
                echo "Skipping already existing translation of original '${original}'".PHP_EOL;
            }
        }
    }
138524
public function upgradeCoreData()
    {
        $e = $this->getPackageEntity();
        if ($e !== null) {
            $this->upgradingFromVersion = $e->getPackageVersion();
        }
        parent::upgradeCoreData();
    }
1100796
@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		ApptentiveLog.d(DATABASE, "Upgrade database from %d to %d", oldVersion, newVersion);
		try {
			DatabaseMigrator migrator = createDatabaseMigrator(oldVersion, newVersion);
			if (migrator != null) {
				migrator.onUpgrade(db, oldVersion, newVersion);
			}
		} catch (Exception e) {
			ApptentiveLog.e(DATABASE, e, "Exception while trying to migrate database from %d to %d", oldVersion, newVersion);
			logException(e);

			// if migration failed - create new table
			db.execSQL(SQL_DELETE_PAYLOAD_TABLE);
			onCreate(db);
		}
	}
773973
protected function renameDatabaseTableField($table, $oldFieldName, $newFieldName)
    {
        $title = 'Renaming "' . $table . ':' . $oldFieldName . '" to "' . $table . ':' . $newFieldName . '": ';

        $currentTableFields = $this->databaseConnection->admin_get_fields($table);

        if ($currentTableFields[$newFieldName]) {
            $message = 'Field ' . $table . ':' . $newFieldName . ' already existing.';
            $status = FlashMessage::OK;
        } else {
            if (!$currentTableFields[$oldFieldName]) {
                $message = 'Field ' . $table . ':' . $oldFieldName . ' not existing';
                $status = FlashMessage::ERROR;
            } else {
                $sql = 'ALTER TABLE ' . $table . ' CHANGE COLUMN ' . $oldFieldName . ' ' . $newFieldName . ' ' .
                    $currentTableFields[$oldFieldName]['Type'];

                if ($this->databaseConnection->admin_query($sql) === false) {
                    $message = ' SQL ERROR: ' . $this->databaseConnection->sql_error();
                    $status = FlashMessage::ERROR;
                } else {
                    $message = 'OK!';
                    $status = FlashMessage::OK;
                }
            }
        }

        $this->addMessage($status, $title, $message);

        return $status;
    }
1278080
public function upgradeDatabase()
    {
        $timezone = \Config::get('app.timezone');
        if ($timezone) {
            // We have a legacy timezone we need to move into the site.
            $site = \Core::make('site')->getSite();
            $config = $site->getConfigRepository();
            $config->save('timezone', $timezone);
        }

        // Add the new dashboard page to update language files
        $this->createSinglePage('/dashboard/system/basics/multilingual/update', 'Update Languages', ['exclude_nav' => true, 'meta_keywords' => 'languages, update, gettext, translation']);
    }