laravel-migrations-generator icon indicating copy to clipboard operation
laravel-migrations-generator copied to clipboard

Need virtual column support

Open CloudyCity opened this issue 4 years ago • 0 comments

Original migration:

Schema::create('voucher', function (Blueprint $table) {
     $table->increments('id');
    $table->unsignedDecimal('money')->nullable()->virtualAs('`config`->>"$.money"');
    $table->json('config')->nullable();
    $table->timestamps();
});

To MySQL:

CREATE TABLE `pro_voucher` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `money` decimal(8,2) unsigned GENERATED ALWAYS AS (json_unquote(json_extract(`config`,'$.money'))) VIRTUAL,
    `config` json DEFAULT NULL,
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
);

Generate:

Schema::create('voucher', function (Blueprint $table) {
    $table->increments('id');
    $table->decimal('money')->unsigned()->nullable();
    $table->json('config')->nullable();
    $table->timestamps();
});

This component not support virtual column in mysql. It seem like not easy to implement, but if someone did that will be great!

CloudyCity avatar Jan 22 '21 10:01 CloudyCity