spiral / app

Spiral Framework Skeleton HTTP Application: Queue, Console, Cycle ORM
https://spiral.dev/
MIT License
191 stars 20 forks source link

How to add BigInt as primary auto_increment key? #16

Closed sujit-baniya closed 4 years ago

sujit-baniya commented 4 years ago

how to add BigInt as primary auto increment key in migration?

Also I don't see the option to add Auto Increment as option.

How to add other options for fields in migration like:

wolfy-j commented 4 years ago

Hi,

you can use primary and bigPrimary. If you want to use UUID you can use alternative declaration: https://cycle-orm.dev/docs/advanced-uuid

To use auto-timestamps you have to use your own mapper, the example is here: https://cycle-orm.dev/docs/advanced-timestamp

You do not need to write migrations manually, use the command for that:

$ php app.php cycle:migrate
sujit-baniya commented 4 years ago

So I can't define timstamp iis simple way

sujit-baniya commented 4 years ago

If I use mapper something like this:

/**
 * @Cycle\Entity(repository="\App\Repository\AccountRepository", mapper="TimestampedMapper")
 */
class Account

Will the fields: created_at and updated_at automatically defined or I need to define it like this way

<?php
/**
 * {project-name}
 * 
 * @author {author-name}
 */
declare(strict_types=1);

namespace App\Database;

use Cycle\Annotated\Annotation as Cycle;

/**
 * @Cycle\Entity(repository="\App\Repository\AccountRepository", mapper="TimestampedMapper")
 */
class Account
{
    /**
     * @Cycle\Column(type = "primary")
     */
    public $id;

    /**
     * @Cycle\Column(type = "string")
     */
    public $name;

    /**
     * @Cycle\Column(type = "timestamp", default="CURRENT_TIMESTAMP")
     */
    public $created_at;

    /**
     * @Cycle\Column(type = "timestamp", default="CURRENT_TIMESTAMP")
     */
    public $updated_at;
}
wolfy-j commented 4 years ago

If you use second example from article with Table annotation columns will be added automatically but you still have to declare fields. We do not have one liner for it yet.

wolfy-j commented 4 years ago

Do not use timestams unless you want to stick to one database type only.

wolfy-j commented 4 years ago

https://spiral.dev/docs/database-errata#timestamps

sujit-baniya commented 4 years ago

oh okay! Thanks