You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@airflow.apache.org by Feng Lu <fe...@google.com.INVALID> on 2018/08/24 06:01:39 UTC

explicit_defaults_for_timestamp for mysql

Hi all,

After reading the MySQL documentation on the
exlicit_defaults_for_timestamp, it appears that we can skip the check
on explicit_defaults_for_timestamp
= 1
<https://github.com/apache/incubator-airflow/blob/master/airflow/migrations/versions/0e2a74e0fc9f_add_time_zone_awareness.py#L43>
by
setting the column to accept NULL explicitly. For example:

op.alter_column(table_name='chart', column_name='last_modified',
type_=mysql.TIMESTAMP(fsp=6)) -->
op.alter_column(table_name='chart', column_name='last_modified',
type_=mysql.TIMESTAMP(fsp=6), nullable=True)

Here's why:
From MySQL doc (when explicit_defaults_for_timestamp is set to True):
"TIMESTAMP columns not explicitly declared with the NOT NULL attribute are
automatically declared with the NULL attribute and permit NULL values.
Assigning such a column a value of NULL sets it to NULL, not the current
timestamp."

Thanks and happy to shoot a PR if it makes sense.

Feng

Re: explicit_defaults_for_timestamp for mysql

Posted by Feng Lu <fe...@google.com.INVALID>.
Bolke, a gentle ping..
Thank you.

On Thu, Aug 23, 2018, 23:01 Feng Lu <fe...@google.com> wrote:

> Hi all,
>
> After reading the MySQL documentation on the
> exlicit_defaults_for_timestamp, it appears that we can skip the check on explicit_defaults_for_timestamp
> = 1
> <https://github.com/apache/incubator-airflow/blob/master/airflow/migrations/versions/0e2a74e0fc9f_add_time_zone_awareness.py#L43> by
> setting the column to accept NULL explicitly. For example:
>
> op.alter_column(table_name='chart', column_name='last_modified',
> type_=mysql.TIMESTAMP(fsp=6)) -->
> op.alter_column(table_name='chart', column_name='last_modified',
> type_=mysql.TIMESTAMP(fsp=6), nullable=True)
>
> Here's why:
> From MySQL doc (when explicit_defaults_for_timestamp is set to True):
> "TIMESTAMP columns not explicitly declared with the NOT NULL attribute are
> automatically declared with the NULL attribute and permit NULL values.
> Assigning such a column a value of NULL sets it to NULL, not the current
> timestamp."
>
> Thanks and happy to shoot a PR if it makes sense.
>
> Feng
>
>
>