cycle / schema-builder

Declarative schema generation for Cycle ORM
MIT License
15 stars 11 forks source link

Respect @Embedded property order when you generate migration's columns #17

Open anlamas opened 3 years ago

anlamas commented 3 years ago

Entities

/**
 * @Cycle\Entity()
 */
class Post
{
    /**
     * @Cycle\Column(type="primary")
     */
    public int $id;

    /**
     * @Cycle\Relation\Embedded(target="Seo")
     */
    public Seo $seo;

    /**
     * @Cycle\Column(type="primary")
     */
    public DateTimeImmutable $createdAt;
}
/**
 * @Embeddable(columnPrefix="seo_")
 */
class Seo
{
    /**
     * @Cycle\Column(type="string", name="title", nullable=true)
     */
    public ?string $title;

    /**
     * @Cycle\Column(type="string", name="description", nullable=true)
     */
    public ?string $description;

    /**
     * @Cycle\Column(type="string", name="keywords", nullable=true)
     */
    public ?string $keywords;
}

Generated migration

$this->table('posts')
    ->addColumn('id', 'primary', [
        'nullable' => false,
        'default'  => null
    ])
    ->addColumn('created_at', 'primary', [
        'nullable' => false,
        'default'  => null
    ])
    ->addColumn('seo_title', 'string', [
        'nullable' => true,
        'default'  => null,
        'size'     => 255
    ])
    ->addColumn('seo_description', 'string', [
        'nullable' => true,
        'default'  => null,
        'size'     => 255
    ])
    ->addColumn('seo_keywords', 'string', [
        'nullable' => true,
        'default'  => null,
        'size'     => 255
    ])
    ->setPrimaryKeys(["id", "created_at"])
    ->create();

What i want is that created_at should be generated after Seo columns, i.e. in this case after seo_keywords