Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Fix CURRENT_TIMESTAMP precision bug #32298

Merged
merged 3 commits into from
Apr 9, 2020
Merged

Conversation

jgusta
Copy link
Contributor

@jgusta jgusta commented Apr 8, 2020

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
Member

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.

None yet

3 participants