Skip to content

[7.x] Fix CURRENT_TIMESTAMP precision bug - #32298

Merged
taylorotwell merged 3 commits into
laravel:7.xfrom
jgusta:7.x
Apr 9, 2020
Merged

[7.x] Fix CURRENT_TIMESTAMP precision bug#32298
taylorotwell merged 3 commits into
laravel:7.xfrom
jgusta:7.x

Conversation

@jgusta

@jgusta jgusta commented Apr 8, 2020

Copy link
Copy Markdown
Contributor

This fixes a bug using the MySQL schema grammar. When defining a migration, setting a fractional second precision in a timestamp field in MySQL would fail if the useCurrent() modifier is used.

Example in a migration:

        Schema::create('failed_jobs', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->text('connection');
            $table->text('queue');
            $table->longText('payload');
            $table->longText('exception');
            $table->timestamp('failed_at', 6)->useCurrent();
        });

When migrating produces an error:

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'failed_at' (SQL: create table `failed_jobs` (`id` bigint unsigned not null auto_increment primary key, `connection` text not null, `queue` text not null, `payload` longtext not null, `exception` longtext not null, `failed_at` timestamp(6) default CURRENT_TIMESTAMP not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci' engine = InnoDB ROW_FORMAT=DYNAMIC)

This fix makes sure the precision modifier is added to CURRENT_TIMESTAMP default, if specified.

@GrahamCampbell GrahamCampbell changed the title Fix CURRENT_TIMESTAMP precision bug [7.x] Fix CURRENT_TIMESTAMP precision bug Apr 8, 2020
@GrahamCampbell

Copy link
Copy Markdown
Collaborator

Could you add a test case please?

@taylorotwell
taylorotwell merged commit be09eac into laravel:7.x Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants