cviebrock / sequel-pro-laravel-export

A Sequel Pro / Sequel Ace bundle to generate Laravel migration files from existing tables.
MIT License
921 stars 55 forks source link

DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP #33

Closed hyhnet closed 4 years ago

hyhnet commented 4 years ago

Hi there,

First, thanks for this awesome tool!

lost ON UPDATE CURRENT_TIMESTAMP

For example:

`CREATE TABLE `test` (
  `id` int(10)  NOT NULL,
  `updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

... generates this migration ...

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTestTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('test', function (Blueprint $table) {
            $table->integer('id');
            $table->timestamp('updated')->nullable()->default(\DB::raw('CURRENT_TIMESTAMP'));
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('test');
    }
}

I'm using bundle version 1.6.0 with Sequel Pro 1.1.2 version 4541 (602e11a) on Mysql 5.7.28 (Docker 19.03.5).

Thank you!

cviebrock commented 4 years ago

It's been a while ... how would you represent ON UPDATE CURRENT_TIMESTAMP in Laravel's Schema?

cviebrock commented 4 years ago

Actually, it looks like if you drop the ->nullable() for that column, running the migration should give you the correct ON UPDATE. This is a MySQL thing, not a Laravel thing.

That said, I'll see if I can fix the package to handle this correctly.

cviebrock commented 4 years ago

@hyhnet Can you give version 1.7.0 a try?

cviebrock commented 4 years ago

Closing due to no response. Feel free to re-open or comment if you are still having issues.