<commit_before><?php

namespace {{ namespace }}\Migrations\Schema;

use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\MigrationBundle\Migration\Installation;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

/**
 * @SuppressWarnings(PHPMD.TooManyMethods)
 * @SuppressWarnings(PHPMD.ExcessiveClassLength)
 */
class {{ className }} implements Installation
{
    /**
     * {@inheritdoc}
     */
    public function getMigrationVersion()
    {
        return '{{ version }}';
    }

    /**
     * {@inheritdoc}
     */
    public function up(Schema $schema, QueryBag $queries)
    {
        /** Tables generation **/
{% for table in schema.tables if allowedTables is empty or allowedTables[table.name] is defined %}
        $this->{{ 'create' ~ table.name|replace({'_': ' '})|title|replace({' ': ''}) ~ 'Table' }}($schema);
{% endfor %}

        /** Foreign keys generation **/
{% for table in schema.tables if allowedTables is empty or allowedTables[table.name] is defined %}
{% if table.ForeignKeys is not empty %}
        $this->{{ 'add' ~ table.name|replace({'_': ' '})|title|replace({' ': ''}) ~ 'ForeignKeys' }}($schema);
{% endif %}
{% endfor %}
    }
{% for table in schema.tables if allowedTables is empty or allowedTables[table.name] is defined %}
{% set methodName = 'create' ~ table.name|replace({'_': ' '})|title|replace({' ': ''}) ~ 'Table' %}

    /**
     * Create {{ table.name }} table
     *
     * @param Schema $schema
     */
    protected function {{ methodName }}(Schema $schema)
    {
        $table = $schema->createTable('{{ table.name }}');
{% for column in table.columns %}
        $table->addColumn('{{ column.name }}', '{{ column.type.name }}', {{ _self.dumpColumnOptions(column) }});
{% endfor %}
{% for index in table.indexes %}
{% if index.isPrimary %}
        $table->setPrimaryKey({{ _self.dumpArray(index.columns) }});
{% elseif index.isUnique %}
        $table->addUniqueIndex({{ _self.dumpArray(index.columns) }}, '{{ index.name }}');
{% else %}
        $table->addIndex({{ _self.dumpArray(index.columns) }}, '{{ index.name }}', {{ _self.dumpArray(index.flags) }});
{% endif %}
{% endfor %}
    }
{% endfor %}
{% for table in schema.tables if allowedTables is empty or allowedTables[table.name] is defined -%}
{% set methodName = 'add' ~ table.name|replace({'_': ' '})|title|replace({' ': ''}) ~ 'ForeignKeys' %}
{% if table.ForeignKeys is not empty %}

    /**
     * Add {{ table.name }} foreign keys.
     *
     * @param Schema $schema
     */
    protected function {{ methodName }}(Schema $schema)
    {
        $table = $schema->getTable('{{ table.name }}');
{% for foreignKey in table.ForeignKeys %}
        $table->addForeignKeyConstraint(
            $schema->getTable('{{ foreignKey.foreignTableName }}'),
            {{ _self.dumpArray(foreignKey.localColumns) }},
            {{ _self.dumpArray(foreignKey.foreignColumns) }},
            {{ _self.dumpOptionsArray(foreignKey.options) }}
        );
{% endfor %}
    }
{% endif -%}
{% endfor -%}
}{% spaceless %}

{% macro dumpColumnOptions(column) %}
{% spaceless %}
{% set options = oro_migration_get_schema_column_options(column) %}
{% set items = [] %}
{% if options.default is defined %}{% set items = items|merge(["'default' => " ~ _self.dumpString(options.default)]) %}{% endif -%}
{% if options.notnull is defined %}{% set items = items|merge(["'notnull' => " ~ _self.dumpBoolean(options.notnull)]) %}{% endif -%}
{% if options.length is defined %}{% set items = items|merge(["'length' => " ~ _self.dumpInteger(options.length)]) %}{% endif -%}
{% if options.precision is defined %}{% set items = items|merge(["'precision' => " ~ _self.dumpInteger(options.precision)]) %}{% endif -%}
{% if options.scale is defined %}{% set items = items|merge(["'scale' => " ~ _self.dumpInteger(options.scale)]) %}{% endif -%}
{% if options.fixed is defined %}{% set items = items|merge(["'fixed' => " ~ _self.dumpBoolean(options.fixed)]) %}{% endif -%}
{% if options.unsigned is defined %}{% set items = items|merge(["'unsigned' => " ~ _self.dumpBoolean(options.unsigned)]) %}{% endif -%}
{% if options.autoincrement is defined %}{% set items = items|merge(["'autoincrement' => " ~ _self.dumpBoolean(options.autoincrement)]) %}{% endif -%}
{% if options.comment is defined %}{% set items = items|merge(["'comment' => " ~ _self.dumpString(options.comment)]) %}{% endif -%}
[{% for item in items %}{% if not loop.first %}, {% endif %}{{ item|raw }}{% endfor %}]
{% endspaceless %}
{% endmacro %}

{% macro dumpOptionsArray(arrayValues) %}
{% spaceless %}
[{% for valueName, value in arrayValues %}{% if value is null %}'{{ valueName }}' => null, {% elseif value is same as(true) %}'{{ valueName }}' => true, {% elseif value is same as(false) %}'{{ valueName }}' => false, {% else  %}'{{ valueName }}' => '{{value  }}', {% endif %}{% endfor %}]
{% endspaceless %}
{% endmacro %}

{% macro dumpArray(arrayValues) %}
{% spaceless %}
[{% for value in arrayValues %}{% if not loop.first %}, {% endif %}'{{ value }}'{% endfor %}]
{% endspaceless %}
{% endmacro %}

{% macro dumpBoolean(value) %}
{% spaceless %}
    {% if value %}
        true
    {% else %}
        false
    {% endif %}
{% endspaceless %}
{% endmacro %}
<commit_msg>CRM-1610: Create migrations for incompatible initial migrations - fixed generated code array output according to CS<commit_after><?php

namespace {{ namespace }}\Migrations\Schema;

use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\MigrationBundle\Migration\Installation;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

/**
 * @SuppressWarnings(PHPMD.TooManyMethods)
 * @SuppressWarnings(PHPMD.ExcessiveClassLength)
 */
class {{ className }} implements Installation
{
    /**
     * {@inheritdoc}
     */
    public function getMigrationVersion()
    {
        return '{{ version }}';
    }

    /**
     * {@inheritdoc}
     */
    public function up(Schema $schema, QueryBag $queries)
    {
        /** Tables generation **/
{% for table in schema.tables if allowedTables is empty or allowedTables[table.name] is defined %}
        $this->{{ 'create' ~ table.name|replace({'_': ' '})|title|replace({' ': ''}) ~ 'Table' }}($schema);
{% endfor %}

        /** Foreign keys generation **/
{% for table in schema.tables if allowedTables is empty or allowedTables[table.name] is defined %}
{% if table.ForeignKeys is not empty %}
        $this->{{ 'add' ~ table.name|replace({'_': ' '})|title|replace({' ': ''}) ~ 'ForeignKeys' }}($schema);
{% endif %}
{% endfor %}
    }
{% for table in schema.tables if allowedTables is empty or allowedTables[table.name] is defined %}
{% set methodName = 'create' ~ table.name|replace({'_': ' '})|title|replace({' ': ''}) ~ 'Table' %}

    /**
     * Create {{ table.name }} table
     *
     * @param Schema $schema
     */
    protected function {{ methodName }}(Schema $schema)
    {
        $table = $schema->createTable('{{ table.name }}');
{% for column in table.columns %}
        $table->addColumn('{{ column.name }}', '{{ column.type.name }}', {{ _self.dumpColumnOptions(column) }});
{% endfor %}
{% for index in table.indexes %}
{% if index.isPrimary %}
        $table->setPrimaryKey({{ _self.dumpArray(index.columns) }});
{% elseif index.isUnique %}
        $table->addUniqueIndex({{ _self.dumpArray(index.columns) }}, '{{ index.name }}');
{% else %}
        $table->addIndex({{ _self.dumpArray(index.columns) }}, '{{ index.name }}', {{ _self.dumpArray(index.flags) }});
{% endif %}
{% endfor %}
    }
{% endfor %}
{% for table in schema.tables if allowedTables is empty or allowedTables[table.name] is defined -%}
{% set methodName = 'add' ~ table.name|replace({'_': ' '})|title|replace({' ': ''}) ~ 'ForeignKeys' %}
{% if table.ForeignKeys is not empty %}

    /**
     * Add {{ table.name }} foreign keys.
     *
     * @param Schema $schema
     */
    protected function {{ methodName }}(Schema $schema)
    {
        $table = $schema->getTable('{{ table.name }}');
{% for foreignKey in table.ForeignKeys %}
        $table->addForeignKeyConstraint(
            $schema->getTable('{{ foreignKey.foreignTableName }}'),
            {{ _self.dumpArray(foreignKey.localColumns) }},
            {{ _self.dumpArray(foreignKey.foreignColumns) }},
            {{ _self.dumpOptionsArray(foreignKey.options) }}
        );
{% endfor %}
    }
{% endif -%}
{% endfor -%}
}{% spaceless %}

{% macro dumpColumnOptions(column) %}
{% spaceless %}
{% set options = oro_migration_get_schema_column_options(column) %}
{% set items = [] %}
{% if options.default is defined %}{% set items = items|merge(["'default' => " ~ _self.dumpString(options.default)]) %}{% endif -%}
{% if options.notnull is defined %}{% set items = items|merge(["'notnull' => " ~ _self.dumpBoolean(options.notnull)]) %}{% endif -%}
{% if options.length is defined %}{% set items = items|merge(["'length' => " ~ _self.dumpInteger(options.length)]) %}{% endif -%}
{% if options.precision is defined %}{% set items = items|merge(["'precision' => " ~ _self.dumpInteger(options.precision)]) %}{% endif -%}
{% if options.scale is defined %}{% set items = items|merge(["'scale' => " ~ _self.dumpInteger(options.scale)]) %}{% endif -%}
{% if options.fixed is defined %}{% set items = items|merge(["'fixed' => " ~ _self.dumpBoolean(options.fixed)]) %}{% endif -%}
{% if options.unsigned is defined %}{% set items = items|merge(["'unsigned' => " ~ _self.dumpBoolean(options.unsigned)]) %}{% endif -%}
{% if options.autoincrement is defined %}{% set items = items|merge(["'autoincrement' => " ~ _self.dumpBoolean(options.autoincrement)]) %}{% endif -%}
{% if options.comment is defined %}{% set items = items|merge(["'comment' => " ~ _self.dumpString(options.comment)]) %}{% endif -%}
[{{ items|join(', ')|raw }}]
{% endspaceless %}
{% endmacro %}

{% macro dumpOptionsArray(arrayValues) %}
{% spaceless %}
{% set items = [] %}
{% for valueName, value in arrayValues %}
    {% if value is null %}
        {% set items = items|merge(["'" ~ valueName ~ "' => null"]) %}
    {% elseif value is same as(true) %}
        {% set items = items|merge(["'" ~ valueName ~ "' => true"]) %}
    {% elseif value is same as(false) %}
        {% set items = items|merge(["'" ~ valueName ~ "' => false"]) %}
    {% else  %}
        {% set items = items|merge(["'" ~ valueName ~ "' => '" ~ value ~ "'"]) %}
    {% endif %}
{% endfor %}
[{{ items|join(', ')|raw }}]
{% endspaceless %}
{% endmacro %}

{% macro dumpArray(arrayValues) %}
{% spaceless %}
[{% for value in arrayValues %}{% if not loop.first %}, {% endif %}'{{ value }}'{% endfor %}]
{% endspaceless %}
{% endmacro %}

{% macro dumpBoolean(value) %}
{% spaceless %}
    {% if value %}
        true
    {% else %}
        false
    {% endif %}
{% endspaceless %}
{% endmacro %}

{'fraction_non_alphanumeric': 0.20682263025445055, 'fraction_numerical': 0.0003728213253798117, 'mean_word_length': 3.6896853146853146, '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': '6347600', 'n_tokens_mistral': 3630, 'n_tokens_neox': 3321, 'n_words': 730}