Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions templates/bake/config/skeleton-anonymous.twig
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,11 @@ return new class extends BaseMigration
*/
public function change(): void
{
{% for table in tables %}
$table = $this->table('{{ table }}');
{% if tableMethod != 'drop' %}
{% if columnMethod == 'removeColumn' %}
{% for column, config in columns['fields'] %}
$table->{{ columnMethod }}('{{ column }}');
{% endfor %}
{% for column, config in columns['indexes'] %}
$table->{{ indexMethod }}([{{
Migration.stringifyList(config['columns']) | raw
}}]);
{% endfor %}
{% else %}
{% for column, config in columns['fields'] %}
$table->{{ columnMethod }}('{{ column }}', '{{ config['columnType'] }}', [{{
Migration.stringifyList(config['options'], {'indent': 3}, wantedOptions) | raw
}}]);
{% endfor %}
{% for column, config in columns['indexes'] %}
$table->{{ indexMethod }}([{{
Migration.stringifyList(config['columns'], {'indent': 3}) | raw }}
], [{{
Migration.stringifyList(config['options'], {'indent': 3}) | raw
}}]);
{% endfor %}
{% if tableMethod == 'create' and columns['primaryKey'] is not empty %}
$table->addPrimaryKey([{{
Migration.stringifyList(columns['primaryKey'], {'indent': 3}) | raw
}}]);
{% endif %}
{% endif %}
{% endif %}
$table->{{ tableMethod }}(){% if tableMethod == 'drop' %}->save(){% endif %};
{% endfor %}
{{ element('Migrations.change-method-body', {
columnMethod: columnMethod,
indexMethod: indexMethod,
tableMethod: tableMethod,
wantedOptions: wantedOptions,
}) }}
}
};
40 changes: 6 additions & 34 deletions templates/bake/config/skeleton.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,11 @@ class {{ name }} extends BaseMigration
*/
public function change(): void
{
{% for table in tables %}
$table = $this->table('{{ table }}');
{%~ if tableMethod != 'drop' %}
{%~ if columnMethod == 'removeColumn' %}
{%~ for column, config in columns['fields'] %}
$table->{{ columnMethod }}('{{ column }}');
{%~ endfor %}
{%~ for column, config in columns['indexes'] %}
$table->{{ indexMethod }}([{{
Migration.stringifyList(config['columns']) | raw
}}]);
{%~ endfor %}
{%~ else %}
{%~ for column, config in columns['fields'] %}
$table->{{ columnMethod }}('{{ column }}', '{{ config['columnType'] }}', [{{
Migration.stringifyList(config['options'], {'indent': 3}, wantedOptions) | raw
}}]);
{%~ endfor %}
{%~ for column, config in columns['indexes'] %}
$table->{{ indexMethod }}([{{
Migration.stringifyList(config['columns'], {'indent': 3}) | raw }}
], [{{
Migration.stringifyList(config['options'], {'indent': 3}) | raw
}}]);
{%~ endfor %}
{%~ if tableMethod == 'create' and columns['primaryKey'] is not empty %}
$table->addPrimaryKey([{{
Migration.stringifyList(columns['primaryKey'], {'indent': 3}) | raw
}}]);
{%~ endif %}
{%~ endif %}
{% endif %}
$table->{{ tableMethod }}(){% if tableMethod == 'drop' %}->save(){% endif %};
{% endfor %}
{{ element('Migrations.change-method-body', {
columnMethod: columnMethod,
indexMethod: indexMethod,
tableMethod: tableMethod,
wantedOptions: wantedOptions,
}) }}
}
}
49 changes: 49 additions & 0 deletions templates/bake/element/change-method-body.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{#
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 5.0.0
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/
#}
{% for table in tables %}
$table = $this->table('{{ table }}');
{%~ if tableMethod != 'drop' %}
{%~ if columnMethod == 'removeColumn' %}
{%~ for column, config in columns['fields'] %}
$table->{{ columnMethod }}('{{ column }}');
{%~ endfor %}
{%~ for column, config in columns['indexes'] %}
$table->{{ indexMethod }}([{{
Migration.stringifyList(config['columns']) | raw
}}]);
{%~ endfor %}
{%~ else %}
{%~ for column, config in columns['fields'] %}
$table->{{ columnMethod }}('{{ column }}', '{{ config['columnType'] }}', [{{
Migration.stringifyList(config['options'], {'indent': 3}, wantedOptions) | raw
}}]);
{%~ endfor %}
{%~ for column, config in columns['indexes'] %}
$table->{{ indexMethod }}([{{
Migration.stringifyList(config['columns'], {'indent': 3}) | raw }}
], [{{
Migration.stringifyList(config['options'], {'indent': 3}) | raw
}}]);
{%~ endfor %}
{%~ if tableMethod == 'create' and columns['primaryKey'] is not empty %}
$table->addPrimaryKey([{{
Migration.stringifyList(columns['primaryKey'], {'indent': 3}) | raw
}}]);
{%~ endif %}
{%~ endif %}
{% endif %}
$table->{{ tableMethod }}(){% if tableMethod == 'drop' %}->save(){% endif %};
{%- endfor -%}
1 change: 1 addition & 0 deletions tests/comparisons/Migration/testNoContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class NoContents extends BaseMigration
*/
public function change(): void
{

}
}
Loading