Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Always put primary key first in generated columns #29

Open
vladgorenkin opened this issue Sep 24, 2021 · 3 comments
Open

Always put primary key first in generated columns #29

vladgorenkin opened this issue Sep 24, 2021 · 3 comments

Comments

@vladgorenkin
Copy link

Primary key does not always come first in generated migrations:

<?php

declare(strict_types=1);

namespace App;

use Cycle\Annotated\Annotation as Cycle;

trait UuidTrait
{
    /**
     * @Cycle\Column(type="uuid", primary=true)
     */
    public string $id;
}

trait CreationTimeTrait
{
    /**
     * @Cycle\Column(type="datetime", nullable=true)
     */
    public \DateTimeImmutable $creationTime;
}

/**
 * @Cycle\Entity()
 */
class Export
{
    use CreationTimeTrait;
    use UuidTrait;

    #[Cycle\Column(type: 'text')]
    public string $title;

    #[Cycle\Column(type: 'text', nullable: true)]
    public ?string $filePath = null;

    #[Cycle\Column(type: 'string')]
    public string $state;
}

Code above results in this migration:

$this->table('exports')
    ->addColumn('title', 'text', [
        'nullable' => false,
        'default'  => null
    ])
    ->addColumn('file_path', 'text', [
        'nullable' => true,
        'default'  => null
    ])
    ->addColumn('state', 'string', [
        'nullable' => false,
        'default'  => null,
        'size'     => 255
    ])
    ->addColumn('creation_time', 'datetime', [
        'nullable' => true,
        'default'  => null
    ])
    ->addColumn('id', 'uuid', [
        'nullable' => false,
        'default'  => null
    ])
    ->setPrimaryKeys(["id"])
    ->create();

Id is the last column of the table so it's not very convenient to browse this table in DB client

@vladgorenkin
Copy link
Author

Is there a problem with this issue?

@SerafimArts
Copy link
Contributor

@vladgorenkin Nope. At the moment, there are higher priority tasks for the release of Cycle 2.0. So most likely this one will already fall into the 2.x branch.

@vladgorenkin
Copy link
Author

Got it, thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants