kitloong / laravel-migrations-generator

Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.
MIT License
2.51k stars 278 forks source link

Type of DATETIME(2) is not being correctly represented by generate command #237

Closed moseslecce closed 1 week ago

moseslecce commented 1 week ago

Describe the bug When running the migrate:generate command the resulting migration code does not generate the correct code.

To Reproduce Steps to reproduce the behavior:

  1. Create table date_test:
CREATE TABLE `date_test` (
  `id` int NOT NULL AUTO_INCREMENT,
  `updated_datetime_2` datetime(2) DEFAULT CURRENT_TIMESTAMP(2) ON UPDATE CURRENT_TIMESTAMP(2),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;
  1. Run php artisan migrate:generate

  2. Open resulting migration file to find the following code:

    public function up(): void
    {
        Schema::create('date_test', function (Blueprint $table) {
            $table->integer('id', true);
            $table->dateTime('updated_datetime_2', 2)->nullable()->default('CURRENT_TIMESTAMP(2)');
        });
    }

Expected behavior I would expect the updated_datetime_2 field to use the useCurrentOnUpdate method and the useCurrent() method to achieve the defaults for this field.

$table->dateTime('updated_datetime_2', 2)->nullable()->useCurrent()->useCurrentOnUpdate();

Details (please complete the following information):

Additional context The generated code attempts to put everything as a string, into the default function. This creates a syntax error.

kitloong commented 1 week ago

Thank you @moseslecce . This has been fixed and release in v7.0.6