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

scheme.xml wrongly generate default value for CURRENT_TIMESTAMP(6) #1905

Open
Brekeke opened this issue Aug 26, 2022 · 3 comments
Open

scheme.xml wrongly generate default value for CURRENT_TIMESTAMP(6) #1905

Brekeke opened this issue Aug 26, 2022 · 3 comments

Comments

@Brekeke
Copy link
Contributor

Brekeke commented Aug 26, 2022

If I set in SQL default value for timestamp data type column as current_timestamp(6) it's generated like:

<column name="created" phpName="Created" type="TIMESTAMP" size="6" defaultValue="current_timestamp(6)"/>

But when is called module:build from that scheme.xml it return this error:

conhost_2022-08-26_12-47-21

When I change defaultValue to defaultExpr in scheme.xml manually it works. Working part of code looks like:

<column name="created" phpName="Created" type="TIMESTAMP" size="6" defaultExpr="current_timestamp(6)"/>

So issue is in generator of scheme.xml which wrongly use defaultValue for current_timestamp(6) and another similar values instead of defaultExpr like it do for normal current_timestamp without length definition.

If is possible fix it, should be nice, thanks :-)

@mringler
Copy link
Contributor

Yes, that is a bit confusing. But I think it is the expected behavior according to the docs:

  • defaultValue The default value that the object will have for this column in the PHP instance after creating a “new Object”. This value is always interpreted as a string.
  • defaultExpr The default value for this column as expressed in SQL. This value is used solely for the “sql” target which builds your database from the schema.xml file. The defaultExpr is the SQL expression used as the “default” for the column.

I think defaultValue has to be something that PHP understands, like new DateTime(), and if you want to use a default value on database level, you need to use defaultExpr, as you do now, and it seems to work.

So it sounds like it is working as expected, but maybe I just misunderstand your issue, then feel free to clarify.

@adjenks
Copy link

adjenks commented Oct 11, 2022

now() as a default value in postgres in a date column also fails when trying to run model:build.
Changing it to defaultExpr also fixes it for me.

@adjenks
Copy link

adjenks commented Oct 11, 2022

Actually, it looks like most of my date columns set to now() were generated as defaultExpr but just one of them wasn't.
This particular one has brackets around it, so perhaps it was interpreted as being a value for some reason. It's defined like so:
date_valid date NOT NULL DEFAULT (now())::date

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

No branches or pull requests

3 participants