<commit_before><?php
/**
 * This file is part of HitTracker.
 *
 * HitTracker is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @copyright 2014 <<EMAIL>>
 * @license AGPL-3
 */

namespace DoctrineMigrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

class Version20150507061327 extends AbstractMigration
{
    private function upPostgreSQL(Schema $schema): void
    {
        $stmts = [];

        $stmts[] = 'CREATE TABLE sylius_settings (
                        id INT GENERATED BY DEFAULT AS IDENTITY,
                        schema_alias VARCHAR(255) NOT NULL,
                        namespace VARCHAR(255),
                        parameters JSON NOT NULL,
                        PRIMARY KEY(id)
                   )';
        $stmts[] = 'CREATE UNIQUE INDEX settings_idx ON sylius_settings (schema_alias, namespace)';

        $stmts[] = 'CREATE TABLE sessions (
                        session_id VARCHAR(128) NOT NULL,
                        session_data BYTEA NOT NULL,
                        session_time INT NOT NULL,
                        session_lifetime INT NOT NULL,
                        PRIMARY KEY(session_id)
                  )';
        $stmts[] = 'CREATE TABLE game_players (
                      id INT GENERATED BY DEFAULT AS IDENTITY,
                      game_id INT DEFAULT NULL,
                      unit_id INT DEFAULT NULL,
                      team VARCHAR(255) DEFAULT NULL,
                      name VARCHAR(255) NOT NULL,
                      hit_points INT NOT NULL,
                      score INT NOT NULL,
                      zone_hits JSONB NOT NULL,
                      created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                      updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
                      PRIMARY KEY(id)
                  )';
        $stmts[] = 'CREATE INDEX idx_player_game_id ON game_players (game_id)';
        $stmts[] = 'CREATE INDEX idx_player_unit_id ON game_players (unit_id)';
        $stmts[] = 'CREATE UNIQUE INDEX idx_player_game_unit ON game_players (game_id, unit_id)';

        $stmts[] = 'CREATE TABLE units (
                      id INT GENERATED BY DEFAULT AS IDENTITY,
                      radio_id VARCHAR(17) NOT NULL,
                      unit_type VARCHAR(255) NOT NULL,
                      color VARCHAR(255) DEFAULT NULL,
                      zones INT NOT NULL,
                      active BOOLEAN NOT NULL,
                      created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                      updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
                      PRIMARY KEY(id)
                  )';
        $stmts[] = 'CREATE UNIQUE INDEX idx_unit_radio_id ON units (radio_id)';
        $stmts[] = 'CREATE TABLE games (
                      id INT GENERATED BY DEFAULT AS IDENTITY,
                      arena INT NOT NULL,
                      game_type VARCHAR(255) NOT NULL,
                      length INT NOT NULL,
                      settings JSONB NOT NULL,
                      ends_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                      created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                      PRIMARY KEY(id)
                  )';
        $stmts[] = 'ALTER TABLE game_players ADD CONSTRAINT FK_players_games
                  FOREIGN KEY (game_id) REFERENCES games (id)
                  ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE';
        $stmts[] = 'ALTER TABLE game_players ADD CONSTRAINT fk_players_unit
                  FOREIGN KEY (unit_id) REFERENCES units (id)
                  NOT DEFERRABLE INITIALLY IMMEDIATE';

        foreach ($stmts as $stmt) {
            $this->addSql($stmt);
        }
    }

    private function upSqlite(Schema $schema): void
    {
        $stmts = [];

        $stmts[] = 'CREATE TABLE game_players (
                        id INTEGER NOT NULL,
                        game_id INTEGER DEFAULT NULL,
                        unit_id INTEGER DEFAULT NULL,
                        team VARCHAR(255) DEFAULT NULL,
                        name VARCHAR(255) NOT NULL,
                        hit_points INTEGER NOT NULL,
                        zone_hits CLOB NOT NULL --(DC2Type:json_array)
                        ,score INTEGER NOT NULL,
                        created_at DATETIME NOT NULL,
                        updated_at DATETIME DEFAULT NULL,
                        PRIMARY KEY(id)
                   )';
        $stmts[] = 'CREATE INDEX idx_player_game_id ON game_players (game_id)';
        $stmts[] = 'CREATE INDEX idx_player_unit_id ON game_players (unit_id)';
        $smmts[] = 'CREATE UNIQUE INDEX idx_player_game_unit ON game_players (game_id, unit_id)';

        $stmts[] = 'CREATE TABLE games (
                        id INTEGER NOT NULL,
                        arena INTEGER NOT NULL,
                        settings CLOB NOT NULL --(DC2Type:json_document)
                        ,ends_at DATETIME NOT NULL,
                        created_at DATETIME NOT NULL,
                        game_type VARCHAR(255) NOT NULL,
                        PRIMARY KEY(id)
                   )';

        $stmts[] = 'CREATE TABLE units (
                        id INTEGER NOT NULL,
                        radio_id VARCHAR(17) NOT NULL,
                        unit_type VARCHAR(255) NOT NULL,
                        color VARCHAR(255) DEFAULT NULL,
                        zones INTEGER NOT NULL,
                        active BOOLEAN NOT NULL,
                        created_at DATETIME NOT NULL,
                        updated_at DATETIME DEFAULT NULL,
                        PRIMARY KEY(id)
                   )';
        $stmts[] = 'CREATE UNIQUE INDEX idx_unit_radio_id ON units (radio_id)';

        $stmts[] = 'CREATE TABLE sylius_settings (
                        id INTEGER NOT NULL,
                        schema_alias VARCHAR(255) NOT NULL,
                        namespace VARCHAR(255) DEFAULT NULL,
                        parameters CLOB NOT NULL --(DC2Type:json_array)
                        , PRIMARY KEY(id)
                   )';
        $stmts[] = 'CREATE UNIQUE INDEX settings_idx ON sylius_settings (schema_alias, namespace)';

        foreach ($stmts as $stmt) {
            $this->addSql($stmt);
        }
    }

    public function up(Schema $schema)
    {
        switch ($this->connection->getDatabasePlatform()->getName()) {
            case 'sqlite':
                $this->upSqlite($schema);
                break;
            default:
                $this->upPostgreSQL($schema);
        }
    }

    public function down(Schema $schema)
    {
        $stmts = [];

        switch ($this->connection->getDatabasePlatform()->getName()) {
            case 'sqlite':
                $stmts[] = 'DROP TABLE game_players';
                $stmts[] = 'DROP TABLE games';
                $stmts[] = 'DROP TABLE units';
                $stmts[] = 'DROP TABLE sylius_settings';
                break;
            default:
                $stmts[] = 'CREATE SCHEMA public';
                $stmts[] = 'ALTER TABLE game_players DROP CONSTRAINT fk_players_units';
                $stmts[] = 'ALTER TABLE game_players DROP CONSTRAINT fk_players_games';
                $stmts[] = 'DROP TABLE sessions';
                $stmts[] = 'DROP TABLE game_players';
                $stmts[] = 'DROP TABLE units';
                $stmts[] = 'DROP TABLE games';
                $stmts[] = 'DROP TABLE sylius_settings_parameter';
        }

        foreach ($stmts as $stmt) {
            $this->addSql($stmt);
        }
    }
}<commit_msg>fix table name in down migration<commit_after><?php
/**
 * This file is part of HitTracker.
 *
 * HitTracker is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @copyright 2014 <<EMAIL>>
 * @license AGPL-3
 */

namespace DoctrineMigrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

class Version20150507061327 extends AbstractMigration
{
    private function upPostgreSQL(Schema $schema): void
    {
        $stmts = [];

        $stmts[] = 'CREATE TABLE sylius_settings (
                        id INT GENERATED BY DEFAULT AS IDENTITY,
                        schema_alias VARCHAR(255) NOT NULL,
                        namespace VARCHAR(255),
                        parameters JSON NOT NULL,
                        PRIMARY KEY(id)
                   )';
        $stmts[] = 'CREATE UNIQUE INDEX settings_idx ON sylius_settings (schema_alias, namespace)';

        $stmts[] = 'CREATE TABLE sessions (
                        session_id VARCHAR(128) NOT NULL,
                        session_data BYTEA NOT NULL,
                        session_time INT NOT NULL,
                        session_lifetime INT NOT NULL,
                        PRIMARY KEY(session_id)
                  )';
        $stmts[] = 'CREATE TABLE game_players (
                      id INT GENERATED BY DEFAULT AS IDENTITY,
                      game_id INT DEFAULT NULL,
                      unit_id INT DEFAULT NULL,
                      team VARCHAR(255) DEFAULT NULL,
                      name VARCHAR(255) NOT NULL,
                      hit_points INT NOT NULL,
                      score INT NOT NULL,
                      zone_hits JSONB NOT NULL,
                      created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                      updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
                      PRIMARY KEY(id)
                  )';
        $stmts[] = 'CREATE INDEX idx_player_game_id ON game_players (game_id)';
        $stmts[] = 'CREATE INDEX idx_player_unit_id ON game_players (unit_id)';
        $stmts[] = 'CREATE UNIQUE INDEX idx_player_game_unit ON game_players (game_id, unit_id)';

        $stmts[] = 'CREATE TABLE units (
                      id INT GENERATED BY DEFAULT AS IDENTITY,
                      radio_id VARCHAR(17) NOT NULL,
                      unit_type VARCHAR(255) NOT NULL,
                      color VARCHAR(255) DEFAULT NULL,
                      zones INT NOT NULL,
                      active BOOLEAN NOT NULL,
                      created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                      updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
                      PRIMARY KEY(id)
                  )';
        $stmts[] = 'CREATE UNIQUE INDEX idx_unit_radio_id ON units (radio_id)';
        $stmts[] = 'CREATE TABLE games (
                      id INT GENERATED BY DEFAULT AS IDENTITY,
                      arena INT NOT NULL,
                      game_type VARCHAR(255) NOT NULL,
                      length INT NOT NULL,
                      settings JSONB NOT NULL,
                      ends_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                      created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                      PRIMARY KEY(id)
                  )';
        $stmts[] = 'ALTER TABLE game_players ADD CONSTRAINT FK_players_games
                  FOREIGN KEY (game_id) REFERENCES games (id)
                  ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE';
        $stmts[] = 'ALTER TABLE game_players ADD CONSTRAINT fk_players_unit
                  FOREIGN KEY (unit_id) REFERENCES units (id)
                  NOT DEFERRABLE INITIALLY IMMEDIATE';

        foreach ($stmts as $stmt) {
            $this->addSql($stmt);
        }
    }

    private function upSqlite(Schema $schema): void
    {
        $stmts = [];

        $stmts[] = 'CREATE TABLE game_players (
                        id INTEGER NOT NULL,
                        game_id INTEGER DEFAULT NULL,
                        unit_id INTEGER DEFAULT NULL,
                        team VARCHAR(255) DEFAULT NULL,
                        name VARCHAR(255) NOT NULL,
                        hit_points INTEGER NOT NULL,
                        zone_hits CLOB NOT NULL --(DC2Type:json_array)
                        ,score INTEGER NOT NULL,
                        created_at DATETIME NOT NULL,
                        updated_at DATETIME DEFAULT NULL,
                        PRIMARY KEY(id)
                   )';
        $stmts[] = 'CREATE INDEX idx_player_game_id ON game_players (game_id)';
        $stmts[] = 'CREATE INDEX idx_player_unit_id ON game_players (unit_id)';
        $smmts[] = 'CREATE UNIQUE INDEX idx_player_game_unit ON game_players (game_id, unit_id)';

        $stmts[] = 'CREATE TABLE games (
                        id INTEGER NOT NULL,
                        arena INTEGER NOT NULL,
                        settings CLOB NOT NULL --(DC2Type:json_document)
                        ,ends_at DATETIME NOT NULL,
                        created_at DATETIME NOT NULL,
                        game_type VARCHAR(255) NOT NULL,
                        PRIMARY KEY(id)
                   )';

        $stmts[] = 'CREATE TABLE units (
                        id INTEGER NOT NULL,
                        radio_id VARCHAR(17) NOT NULL,
                        unit_type VARCHAR(255) NOT NULL,
                        color VARCHAR(255) DEFAULT NULL,
                        zones INTEGER NOT NULL,
                        active BOOLEAN NOT NULL,
                        created_at DATETIME NOT NULL,
                        updated_at DATETIME DEFAULT NULL,
                        PRIMARY KEY(id)
                   )';
        $stmts[] = 'CREATE UNIQUE INDEX idx_unit_radio_id ON units (radio_id)';

        $stmts[] = 'CREATE TABLE sylius_settings (
                        id INTEGER NOT NULL,
                        schema_alias VARCHAR(255) NOT NULL,
                        namespace VARCHAR(255) DEFAULT NULL,
                        parameters CLOB NOT NULL --(DC2Type:json_array)
                        , PRIMARY KEY(id)
                   )';
        $stmts[] = 'CREATE UNIQUE INDEX settings_idx ON sylius_settings (schema_alias, namespace)';

        foreach ($stmts as $stmt) {
            $this->addSql($stmt);
        }
    }

    public function up(Schema $schema)
    {
        switch ($this->connection->getDatabasePlatform()->getName()) {
            case 'sqlite':
                $this->upSqlite($schema);
                break;
            default:
                $this->upPostgreSQL($schema);
        }
    }

    public function down(Schema $schema)
    {
        $stmts = [];

        switch ($this->connection->getDatabasePlatform()->getName()) {
            case 'sqlite':
                $stmts[] = 'DROP TABLE game_players';
                $stmts[] = 'DROP TABLE games';
                $stmts[] = 'DROP TABLE units';
                $stmts[] = 'DROP TABLE sylius_settings';
                break;
            default:
                $stmts[] = 'CREATE SCHEMA public';
                $stmts[] = 'ALTER TABLE game_players DROP CONSTRAINT fk_players_units';
                $stmts[] = 'ALTER TABLE game_players DROP CONSTRAINT fk_players_games';
                $stmts[] = 'DROP TABLE sessions';
                $stmts[] = 'DROP TABLE game_players';
                $stmts[] = 'DROP TABLE units';
                $stmts[] = 'DROP TABLE games';
                $stmts[] = 'DROP TABLE sylius_settings';
        }

        foreach ($stmts as $stmt) {
            $this->addSql($stmt);
        }
    }
}
{'fraction_non_alphanumeric': 0.0750923514806516, 'fraction_numerical': 0.009447102283049718, 'mean_word_length': 1.4501483679525222, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5616063', 'n_tokens_mistral': 4614, 'n_tokens_neox': 4188, 'n_words': 1351}