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

Liquibase inserts wrong default datetime value into MySql #1395

Open
vaa25-digis opened this issue Sep 10, 2020 · 2 comments · May be fixed by #1407
Open

Liquibase inserts wrong default datetime value into MySql #1395

vaa25-digis opened this issue Sep 10, 2020 · 2 comments · May be fixed by #1407

Comments

@vaa25-digis
Copy link

@vaa25-digis vaa25-digis commented Sep 10, 2020

Environment

Liquibase Version: 4.0.0

Liquibase Integration & Version: spring boot 2.3.2

Liquibase Extension(s) & Version:

Database Vendor & Version: MySql 8.0.15

Operating System Type & Version: Ubuntu 18.04.3

Description

Fail when try to add column with precisioned CURRENT_TIMESTAMP default value

Steps To Reproduce

Run this changelog:

<databaseChangeLog
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd">
    <changeSet  id="10" author="vaa25">
        <createTable tableName="test" schemaName="liquibase">
            <column name="id" type="INT" autoIncrement="true">
                <constraints primaryKey="true"/>
            </column>
            <column name="created_at" type="DATETIME(3)" defaultValueDate="CURRENT_TIMESTAMP(3)">
                <constraints nullable="false"/>
            </column>
        </createTable>
    </changeSet>
</databaseChangeLog>

Actual Behavior

Result of execution:
liquibase.exception.DatabaseException: Invalid default value for 'created_at' [Failed SQL: (1067) CREATE TABLE liquibase.test (id INT AUTO_INCREMENT NOT NULL, created_at datetime(3) DEFAULT NOW() NOT NULL, CONSTRAINT PK_TEST PRIMARY KEY (id))]

Expected/Desired Behavior

Apply correct sql :
CREATE TABLE liquibase.test (id INT AUTO_INCREMENT NOT NULL, created_at datetime(3) DEFAULT NOW(3) NOT NULL, CONSTRAINT PK_TEST PRIMARY KEY (id))

Additional Context

dev.mysql.com/doc/refman/8.0/en/date-and-time-type-syntax.html
An optional fsp value in the range from 0 to 6 may be given to specify fractional seconds precision. A value of 0 signifies that there is no fractional part. If omitted, the default precision is 0.

┆Issue is synchronized with this Jira Bug by Unito

@molivasdat
Copy link
Contributor

@molivasdat molivasdat commented Sep 11, 2020

Hi @vaa25-digis Thank you for writing up this descriptive issue with great steps to reproduce. We will add this to our list of issues to process. In the meantime if you have a fix, please create a PR and we will process that as well.

@pirocraft
Copy link

@pirocraft pirocraft commented Sep 16, 2020

Hi @vaa25-digis, can you simply use
<column name="created_at" type="DATETIME(3)" defaultValueDate="NOW(3)">
instead of
<column name="created_at" type="DATETIME(3)" defaultValueDate="CURRENT_TIMESTAMP(3)">
?

pirocraft added a commit to pirocraft/liquibase that referenced this issue Sep 16, 2020
pirocraft added a commit to pirocraft/liquibase that referenced this issue Sep 16, 2020
pirocraft added a commit to pirocraft/liquibase that referenced this issue Sep 16, 2020
pirocraft added a commit to pirocraft/liquibase that referenced this issue Sep 16, 2020
@pirocraft pirocraft linked a pull request that will close this issue Sep 16, 2020
3 of 7 tasks complete
@molivasdat molivasdat linked a pull request that will close this issue Sep 21, 2020
3 of 7 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.