cycle / annotated

Schema generation using annotated entities and mappers
MIT License
24 stars 13 forks source link

Migration generator not add precision and scale params for decimal column type in Embeddable class 🐛 #102

Open ncodealex opened 3 months ago

ncodealex commented 3 months ago

No duplicates 🥲.

What happened?

Hello ! Thanks for your product !

I'm create embeddable class for my base entity.


#[Embeddable(columnPrefix: 'property_')]
final class ProductProperty
{
    #[Column(type: 'decimal', nullable: false, default: 0, precision: 2, scale: 10)]
    private int $width = 0;

    // and others columns

}

When i generate migration file with the command:

php app.php cycle:migrate

I get such a file that does not include params precision and scale params:

// Parent entity 
final class Product
{
    #[Column(type: 'decimal', nullable: true, precision: 2, scale: 2)]
    private int $minStock = 0;

    #[Embedded(target: 'ProductProperty')]
    private ProductProperty $property;

    public function __construct(){
        $this->property = new ProductProperty();
    }
}

// Generated migration for 'Product'

class OrmDefault503ad0138adb712888e44c220d4cf5aa extends Migration
{

    public function up(): void
    {
        $this->table('product')
->addColumn('min_stock', 'decimal', ['nullable' => true, 'defaultValue' => null, 'precision' => 2, 'scale' => 2]); /// This property in base entity
->addColumn('property_width', 'decimal', ['nullable' => false, 'defaultValue' => 0, 'precision' => 0, 'scale' => 0]) // And this in Embedded entity 
     }

}

I will be grateful for your help!

Version

annotated v4.1.0, orm v2.8.1, PHP 8.3

ORM Schema

No response

ncodealex commented 3 months ago

if i add parameters with attributes we get same behavior


    #[Column(type: 'decimal', nullable: false, default: 0, attributes: ['precision' => 3, 'scale' => 11])]
    private int $width = 0;
roxblnfk commented 3 months ago

could you try #[Column(type: 'decimal(3,11)')]?

ncodealex commented 3 months ago

could you try #[Column(type: 'decimal(3,11)')]?

This work !

Will be generated:

->addColumn('property_width', 'decimal', ['nullable' => false, 'defaultValue' => 0, 'precision' => 3, 'scale' => 11])