<commit_before><?php declare(strict_types=1);

namespace Fusio\Impl\Migrations\Version;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Fusio\Impl\Migrations\MigrationUtil;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20191022185247 extends AbstractMigration
{
    public function up(Schema $schema) : void
    {
        // add new scopes
        $count = $this->connection->fetchColumn('SELECT COUNT(*) AS cnt FROM fusio_scope WHERE name = :name', ['name' => 'backend.account']);
        if (empty($count)) {
            $this->insertScopes();
        }

        // add token column
        $userTable = $schema->getTable('fusio_user');
        if (!$userTable->hasColumn('token')) {
            $userTable->addColumn('token', 'string', ['length' => 255, 'notnull' => false, 'default' => null]);
        }

        // change config length
        $configTable = $schema->getTable('fusio_config');
        $configTable->changeColumn('value', ['length' => 512]);

        // sync
        MigrationUtil::sync($this->connection, function($sql, $params){
            $this->addSql($sql, $params);
        });
    }

    public function down(Schema $schema) : void
    {
    }

    private function insertScopes()
    {
        $scopes = [
            ['name' => 'backend.account', 'description' => 'Option to change the password of your account'],
            ['name' => 'backend.action', 'description' => 'View and manage actions'],
            ['name' => 'backend.app', 'description' => 'View and manage apps'],
            ['name' => 'backend.audit', 'description' => 'View audits'],<commit_msg>move sync to post up<commit_after><?php declare(strict_types=1);

namespace Fusio\Impl\Migrations\Version;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Fusio\Impl\Migrations\MigrationUtil;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20191022185247 extends AbstractMigration
{
    public function up(Schema $schema) : void
    {
        // add new scopes
        $count = $this->connection->fetchColumn('SELECT COUNT(*) AS cnt FROM fusio_scope WHERE name = :name', ['name' => 'backend.account']);
        if (empty($count)) {
            $this->insertScopes();
        }

        // add token column
        $userTable = $schema->getTable('fusio_user');
        if (!$userTable->hasColumn('token')) {
            $userTable->addColumn('token', 'string', ['length' => 255, 'notnull' => false, 'default' => null]);
        }

        // change config length
        $configTable = $schema->getTable('fusio_config');
        $configTable->changeColumn('value', ['length' => 512]);
    }

    public function postUp(Schema $schema)
    {
        // sync
        MigrationUtil::sync($this->connection, function($sql, $params){
            $this->addSql($sql, $params);
        });
    }

    public function down(Schema $schema) : void
    {
    }

    private function insertScopes()
    {
        $scopes = [
            ['name' => 'backend.account', 'description' => 'Option to change the password of your account'],
            ['name' => 'backend.action', 'description' => 'View and manage actions'],
            ['name' => 'backend.app', 'description' => 'View and manage apps'],
            ['name' => 'backend.audit', 'description' => 'View audits'],
{'fraction_non_alphanumeric': 0.15921130076515597, 'fraction_numerical': 0.012360211889346674, 'mean_word_length': 2.814814814814815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1684529', 'n_tokens_mistral': 998, 'n_tokens_neox': 965, 'n_words': 233}