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

Always put primary key first in generated columns #29

@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions