-
-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
status:under discussiontype:questionFurther information is requestedFurther information is requested
Description
The issue
When compiling a migration and an entity uses behaviors, such as CreatedAt and UpdatedAt, the RenderModifiers generator adds these to the table schema first ignoring or not knowing the order in which fields are defined. Which means the migration files need to be manually edited to ensure column ordering reflects the entity fields.
Let me know if this something you see as an issue and I can try and work on a solution.
Potential Solution
cycle/schema-migrations-generator/src/GenerateMigrations.php
public function run(Registry $registry): Registry
{
$databases = [];
foreach ($registry as $e) {
if ($registry->hasTable($e) && !$e->getOptions()->has(SyncTables::READONLY_SCHEMA)) {
// An array of column names in the order fields are listed
$names = array_map(fn(Field $field) => $field->getColumn(), \iterator_to_array($e->getFields()));
// Store the table before modification and passing to $databases
$table = $registry->getTableSchema($e);
// Call newly added method for sorting columns
$table->sortColumns($names);
// Set table with preferred column ordering
$databases[$registry->getDatabase($e)][] = $table;
}
}
...
}cycle/database/src/Schema/AbstractTable.php
public function sortColumns(array $names): void
{
$this->current->sortColumnsByNames($names);
}cycle/database/src/Schema/State.php
public function sortColumnsByNames(array $names): void
{
$sorted = [];
foreach ($names as $name) {
if (isset($this->columns[$name])) {
$sorted[$name] = $this->columns[$name];
}
}
foreach ($this->columns as $name => $column) {
if (! isset($sorted[$name])) {
$sorted[$name] = $column;
}
}
$this->columns = $sorted;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
status:under discussiontype:questionFurther information is requestedFurther information is requested