<commit_before><?php

namespace DoctrineMigrations;

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

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20140509160547 extends AbstractMigration
{

    public function up(Schema $schema)
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "postgresql", "Migration can only be executed safely on 'postgresql'.");

        $this->addSql("DROP INDEX population_unique");
        $this->addSql("ALTER TABLE population ADD questionnaire_id INT DEFAULT NULL");
        $this->addSql("ALTER TABLE population ADD CONSTRAINT FK_B449A008CE07E8FF FOREIGN KEY (questionnaire_id) REFERENCES questionnaire (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE");
        $this->addSql("CREATE INDEX IDX_B449A008CE07E8FF ON population (questionnaire_id)");
        $this->addSql("CREATE UNIQUE INDEX population_unique_official ON population (year, country_id, part_id) WHERE questionnaire_id IS NULL");
        $this->addSql("CREATE UNIQUE INDEX population_unique_non_official ON population (year, country_id, part_id, questionnaire_id) WHERE questionnaire_id IS NOT NULL");

        $objects = array(
            'Population' => array(
                'create' => array('reporter'),
                'read' => array('anonymous', 'member'),
                'update' => array('reporter'),
                'delete' => array('reporter'),
            ),
        );

        foreach ($objects as $object => $actions) {
            foreach ($actions as $action => $roles) {
                $name = $object . '-' . $action;
                $this->addSql('INSERT INTO permission (date_created, name) VALUES (NOW(), ?);', array($name));

                // Give access to defined roles
                foreach ($roles as $role) {
                    $this->addSql("INSERT INTO role_permission (role_id, permission_id) SELECT role.id, permission.id FROM role CROSS JOIN permission WHERE (role.name = ?)AND permission.name = ?;", array($role, $name));
                }
            }
        }

        $this->addSql("ALTER TABLE question ADD alternate_names JSON DEFAULT '[]' NOT NULL;");
        $this->addSql("ALTER TABLE question ALTER description SET DEFAULT '';");
        $this->addSql("CREATE UNIQUE INDEX answerable_question_must_have_unique_filter_within_same_survey ON question (survey_id, filter_id);");
    }

    public function down(Schema $schema)
    {
        $this->throwIrreversibleMigrationException();
    }

}<commit_msg>Allow questions to have no filters #2715<commit_after><?php

namespace DoctrineMigrations;

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

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20140509160547 extends AbstractMigration
{

    public function up(Schema $schema)
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "postgresql", "Migration can only be executed safely on 'postgresql'.");

        $this->addSql("DROP INDEX population_unique");
        $this->addSql("ALTER TABLE population ADD questionnaire_id INT DEFAULT NULL");
        $this->addSql("ALTER TABLE population ADD CONSTRAINT FK_B449A008CE07E8FF FOREIGN KEY (questionnaire_id) REFERENCES questionnaire (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE");
        $this->addSql("CREATE INDEX IDX_B449A008CE07E8FF ON population (questionnaire_id)");
        $this->addSql("CREATE UNIQUE INDEX population_unique_official ON population (year, country_id, part_id) WHERE questionnaire_id IS NULL");
        $this->addSql("CREATE UNIQUE INDEX population_unique_non_official ON population (year, country_id, part_id, questionnaire_id) WHERE questionnaire_id IS NOT NULL");

        $objects = array(
            'Population' => array(
                'create' => array('reporter'),
                'read' => array('anonymous', 'member'),
                'update' => array('reporter'),
                'delete' => array('reporter'),
            ),
        );

        foreach ($objects as $object => $actions) {
            foreach ($actions as $action => $roles) {
                $name = $object . '-' . $action;
                $this->addSql('INSERT INTO permission (date_created, name) VALUES (NOW(), ?);', array($name));

                // Give access to defined roles
                foreach ($roles as $role) {
                    $this->addSql("INSERT INTO role_permission (role_id, permission_id) SELECT role.id, permission.id FROM role CROSS JOIN permission WHERE (role.name = ?)AND permission.name = ?;", array($role, $name));
                }
            }
        }

        $this->addSql("ALTER TABLE question ADD alternate_names JSON DEFAULT '[]' NOT NULL;");
        $this->addSql("ALTER TABLE question ALTER description SET DEFAULT '';");
        $this->addSql("ALTER TABLE question DROP CONSTRAINT answerable_question_must_have_filter;");
        $this->addSql("UPDATE question SET filter_id = NULL WHERE filter_id IN (1, 2, 3, 4);");
        $this->addSql("CREATE UNIQUE INDEX answerable_question_must_have_unique_filter_within_same_survey ON question (survey_id, filter_id);");
    }

    public function down(Schema $schema)
    {
        $this->throwIrreversibleMigrationException();
    }

}
{'fraction_non_alphanumeric': 0.11738026124818578, 'fraction_numerical': 0.013062409288824383, 'mean_word_length': 3.1019345238095237, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '6947864', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1509, 'n_words': 420}