{@inheritdoc}

@see \Concrete\Core\Updater\Migrations\AbstractMigration::upgradeDatabase()
968753
public function upgradeDatabase()
    {
        $this->refreshBlockType('express_form');
        $filesystem = new Filesystem();
        $folder = $filesystem->getRootFolder();
        if ($folder) {
            $this->connection->executeQuery(
                'update btExpressForm set addFilesToFolder = ? where addFilesToFolder IS NULL or addFilesToFolder = 0', [$folder->getTreeNodeID()]
            );
        }
    }
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.');
        }
    }
1317671
public function upgrade(): void
    {
        // These tables were created by webtrees 1.x, and may not exist if we first installed webtrees 2.x
        DB::schema()->dropIfExists('site_access_rule');
        DB::schema()->dropIfExists('next_id');

        // Split the media table into media/media_file so that we can store multiple media
        // files in each media object.
        DB::schema()->create('media_file', static function (Blueprint $table): void {
            $table->integer('id', true);
            $table->string('m_id', 20);
            $table->integer('m_file');
            $table->string('multimedia_file_refn', 248); // GEDCOM only allows 30 characters
            $table->string('multimedia_format', 4);
            $table->string('source_media_type', 15);
            $table->string('descriptive_title', 248);

            $table->index(['m_id', 'm_file']);
            $table->index(['m_file', 'm_id']);
            $table->index(['m_file', 'multimedia_file_refn']);
            $table->index(['m_file', 'multimedia_format']);
            $table->index(['m_file', 'source_media_type']);
            $table->index(['m_file', 'descriptive_title']);
        });

        if (DB::schema()->hasColumn('media', 'm_filename')) {
            (new Builder(DB::connection()))->from('media_file')->insertUsing([
                'm_id',
                'm_file',
                'multimedia_file_refn',
                'multimedia_format',
                'source_media_type',
                'descriptive_title',
            ], static function (Builder $query): void {
                $query->select([
                    'm_id',
                    'm_file',
                    'm_filename',
                    'm_ext',
                    'm_type',
                    'm_titl',
                ])->from('media');
            });

            // SQLite can only drop one column at a time.
            DB::schema()->table('media', static function (Blueprint $table): void {
                $table->dropColumn('m_filename');
            });
            DB::schema()->table('media', static function (Blueprint $table): void {
                $table->dropColumn('m_ext');
            });
            DB::schema()->table('media', static function (Blueprint $table): void {
                $table->dropColumn('m_type');
            });
            DB::schema()->table('media', static function (Blueprint $table): void {
                $table->dropColumn('m_titl');
            });
        }
    }
944748
public function upgradeCoreData()
    {
        $entity = $this->getPackageEntity();
        if ($entity !== null) {
            $em = $this->app->make(EntityManagerInterface::class);
            $entity->setPackageName($this->getPackageName());
            $entity->setPackageDescription($this->getPackageDescription());
            $entity->setPackageVersion($this->getPackageVersion());
            $em->persist($entity);
            $em->flush();
        }
    }
779033
public function upgradeDatabase()
    {
        $config = $this->app->make('config');
        $resolver = $this->app->make(Resolver::class);
        $error = null;
        try {
            list($characterSet, $collation) = $resolver
                ->setCharacterSet((string) $config->get('database.preferred_character_set'))
                ->setCollation((string) $config->get('database.preferred_collation'))
                ->resolveCharacterSetAndCollation($this->connection)
            ;
        } catch (CharacterSetCollationException $x) {
            try {
                list($characterSet, $collation) = $resolver
                    ->setCharacterSet((string) $config->get('database.fallback_character_set'))
                    ->setCollation((string) $config->get('database.fallback_collation'))
                    ->resolveCharacterSetAndCollation($this->connection)
                ;
            } catch (Exception $x) {
                $error = $x;
            }
        } catch (Throwable $x) {
            $error = $x;
        }
        if ($error !== null) {
            $this->output(t('Failed to resolve the database character set and collation: %s', $error->getMessage()));

            return;
        }
        $params = $this->connection->getParams();
        if (isset($params['character_set']) && $params['character_set'] === $characterSet && isset($params['collation']) && $params['collation'] === $collation) {
            return;
        }
        $manager = $this->app->make(Manager::class);
        try {
            $manager->apply(
                $characterSet,
                $collation,
                '',
                '',
                function ($message) {
                    $this->output($message);
                }
            );
        } catch (Exception $x) {
            $this->output(t('Failed to set character sets: %s', $x->getMessage()));
        } catch (Throwable $x) {
            $this->output(t('Failed to set character sets: %s', $x->getMessage()));
        }
    }
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']);
    }
396075
public function upgradeDatabase()
    {
        $this->connection->executeQuery("UPDATE btSearch SET postTo_cID = NULL WHERE postTo_cID IS NOT NULL AND postTo_cID = ''");
        foreach ([
            "postTo_cID NOT REGEXP '^[1-9][0-9]*$'",
            'IFNULL(postTo_cID + 0, 0) < 1',
            'IFNULL(CAST(postTo_cID AS SIGNED), 0) < 1',
        ] as $try) {
            try {
                $this->connection->executeQuery('UPDATE btSearch SET postTo_cID = NULL WHERE postTo_cID IS NOT NULL AND ' . $try);
                break;
            } catch (Exception $foo) {
            }
        }
        $this->refreshBlockType('search');
    }
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);
        }
    }
721420
public function update($db=''){
		if ( empty($db) ){
			$db = $this->db->current;
		}
		if ( bbn\str::check_name($db) ){

      $this->db->clear_all_cache();

			$change = $this->db->current === $db ? false : $this->db->current;
			if ( $change ){
				$this->db->change($db);
			}
			$schema = $this->db->modelize();
			if ( $change ){
				$this->db->change($change);
			}
      /*
			$projects = [];
			$r1 = $this->db->query("SELECT *
			FROM `{$this->admin_db}`.`{$this->prefix}projects`
			WHERE `db` LIKE '$db'");
			while ( $d1 = $r1->get_row() ){
				$projects[$d1['id']] = $d1;
				$projects[$d1['id']]['forms'] = [];
				$r2 = $this->db->query("
					SELECT id
					FROM `{$this->admin_db}`.`{$this->prefix}forms`
					WHERE `id_project` = ?",
					$d1['id']);
				while ( $d2 = $r2->get_row() ){
					$projects[$d1['id']]['forms'][$d2['id']] = $this->get_form_config();
				}
			}
			*/
			$this->db->insert_ignore($this->admin_db.'.'.$this->prefix.'dbs',[
        'id' => $db,
        'db' => $db,
        'host' => $this->db->host
      ]);
      $tab_history = false;
      if ( bbn\appui\history::$is_used && isset($schema[bbn\appui\history::$htable]) ){
        $tab_history = 1;
      }
      if ( !\is_array($schema) ){

        die(var_dump("THIS IS NOT AN ARRAY", $schema));
      }

			foreach ( $schema as $t => $vars ){
        $col_history = $tab_history;
				if ( isset($vars['fields']) ){
          $tmp = explode(".", $t);
          $db = $tmp[0];
          $table = $tmp[1];
					$this->db->insert_update($this->admin_db.'.'.$this->prefix.'tables',[
						'id' => $t,
						'db' => $db,
						'table' => $table
					]);
          if ( $col_history && !array_key_exists(bbn\appui\history::$hcol, $vars['fields']) ){
            $col_history = false;
          }
          foreach ( $vars['fields'] as $col => $f ){
    				$config = new \stdClass();
						if ( $col_history && ($col !== bbn\appui\history::$hcol) ){
							$config->history = 1;
						}
						if ( !empty($f['extra']) ){
							$config->extra = $f['extra'];
						}
						if ( isset($f['signed']) && $f['signed'] == 1 ){
							$config->signed = 1;
						}
						if ( isset($f['null']) && $f['null'] == '1' ){
							$config->null = 1;
						}
						if ( isset($f['maxlength']) && $f['maxlength'] > 0 ){
							$config->maxlength = (int)$f['maxlength'];
						}
						if ( isset($f['keys']) ){
							$config->keys = [];
							foreach ( $f['keys'] as $key ){
								$config->keys[$key] = $vars['keys'][$key];
							}
						}
						$this->db->insert_update($this->admin_db.'.'.$this->prefix.'columns',[
							'id' => $t.'.'.$col,
							'table' => $t,
							'column' => $col,
							'position' => $f['position'],
							'type' => $f['type'],
							'null' => $f['null'],
              'key' => $f['key'],
              'default' => $f['default'],
							'config' => json_encode($config)
						]);
					}
				}
			}
      foreach ( $schema as $t => $vars ){
        if ( isset($vars['keys']) && \is_array($vars['keys']) ){
          foreach ( $vars['keys'] as $k => $arr ){
            $pos = 1;
            foreach ( $arr['columns'] as $c ){
              $this->db->insert_update($this->admin_db.'.'.$this->prefix.'keys', [
                'id' => $t.'.'.$k,
                'key' => $k,
                'table' => $t,
                'column' => $t.'.'.$c,
                'position' => $pos,
                'ref_column' => \is_null($arr['ref_column']) ? null : $arr['ref_db'].'.'.$arr['ref_table'].'.'.$arr['ref_column'],
                'unique' => $arr['unique']
              ]);
              $pos++;
            }
          }
        }
      }
      /*
			foreach ( $projects as $i => $p ){
				$this->db->insert($this->admin_db.'.'.$this->prefix.'projects',[
					'id' => $i,
					'id_client' => $p['id_client'],
					'db' => $p['db'],
					'name' => $p['name'],
					'config' => $p['config']]);
				foreach ( $p['forms'] as $j => $form ){
					$this->db->insert($this->admin_db.'.'.$this->prefix.'forms',[
						'id' => $j,
						'id_project' => $i
					]);
					foreach ( $form as $field ){
						$this->db->insert_ignore($this->admin_db.'.'.$this->prefix.'fields',[
							'id' => $field['id'],
							'id_form' => $j,
							'column' => $field['column'],
							'title' => $field['title'],
							'position' => $field['position'],
							'configuration' => json_encode($field['configuration'])
						]);
					}
				}
			}
       * 
       */
      $this->db->enable_keys();
		}
	}
175929
protected function loadLaravelMigrations($database = []): void
    {
        $options = \is_array($database) ? $database : ['--database' => $database];

        $options['--path'] = 'migrations';

        $migrator = new MigrateProcessor($this, $options);

        $migrator->up();

        $this->app[ConsoleKernel::class]->setArtisan(null);

        $this->beforeApplicationDestroyed(function () use ($migrator) {
            $migrator->rollback();
        });
    }
803961
public function up(Database $db)
    {
        $collection = $db->createCollection($this->collection);

        // Remove index
        $collection->deleteIndex(['domain_1_locale_1_original_1']);

        /** @var array $translatable */
        foreach ($collection->find() as $translatable) {
            $id = $translatable['_id'];
            if (!ctype_xdigit($id)) {
                $newId = sha1($id);
                if ($collection->findOne(['_id' => $newId], ['id'])) {
                    $collection->remove(['_id' => $id]);
                } else {
                    $translatable['_id'] = $newId;
                    $collection->insert($translatable);
                    $collection->remove(['_id' => $id]);
                }
            }
        }
    }
213913
public function upgradeDatabase()
    {
        if ($this->connection->getSchemaManager()->tablesExist('CalendarEventVersions')) {
            $events = (int) $this->connection->fetchColumn('select count(*) from CalendarEventVersions');
        } else {
            $events = null;
        }
        if ($events === null || $events === 0) {
            $this->migrateCalendar();
        }
    }
59829
public function upgrade(): void
    {
        // doctrine/dbal cannot modify tables containing ENUM fields
        $data = DB::table('module_privacy')->get();

        DB::schema()->drop('module_privacy');

        DB::schema()->create('module_privacy', static function (Blueprint $table): void {
            $table->increments('id');
            $table->string('module_name', 32);
            $table->integer('gedcom_id');
            $table->string('interface');
            $table->tinyInteger('access_level');

            $table->unique(['gedcom_id', 'module_name', 'interface']);
            $table->unique(['module_name', 'gedcom_id', 'interface']);

            $table->foreign('module_name')->references('module_name')->on('module')->onDelete('cascade');
            $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade');
        });

        foreach ($data as $datum) {
            DB::table('module_privacy')->insert([
                'module_name'  => $datum->module_name,
                'gedcom_id'    => $datum->gedcom_id,
                'interface'    => self::COMPONENT_TO_INTERFACE[$datum->component],
                'access_level' => $datum->access_level,
            ]);
        }
    }
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,
            ]);
        }
    }
1148686
public function modifyDatabase()
    {
        foreach ($this->getDatabase()->getTables() as $table) {
            if (!$table->hasPrimaryKey()) {
                $b = clone $this;
                $table->addBehavior($b);
            }
        }
    }
1162174
public function update()
    {
        if( !$this->tableName ) {
            throw new LogicException('No table name specified');
        }
        return $this->database->update()
                ->table($this->tableName);
    }
702590
def db_upgrade(version=None):
    """"""
    v1 = get_db_version()
    migrate_api.upgrade(url=db_url, repository=db_repo, version=version)
    v2 = get_db_version()

    if v1 == v2:
        print 'Database already up-to-date.'
    else:
        print 'Upgraded: %s ... %s' % (v1, v2)