phinx icon indicating copy to clipboard operation
phinx copied to clipboard

CURRENT_TIMESTAMP not quoted even for non-datetime columns

Open MasterOdin opened this issue 5 years ago • 2 comments

The following code will throw an error:

        $this->table('test')
            ->addColumn('test_col', 'string', ['default' => 'CURRENT_TIMESTAMP'])
            ->create();

This is because the default value will not be quoted. We can probably update the if check for CURRENT_TIMESTAMP either apply if the column type is a datetime/timestamp, or not if the column is a string. I would probably lean towards doing the former, and then for custom types, the user will just be expected to use a Literal, as the latter does not really leave a good way for a user to handle custom types satisfactorily.

MasterOdin avatar Sep 29 '20 22:09 MasterOdin

is that solved through https://github.com/cakephp/phinx/pull/1882 ?

dereuromark avatar Sep 30 '20 01:09 dereuromark

No. It'll actually make the problem "worse" in that now anything starting with CURRENT_TIMESTAMP would fail (e.g. CURRENT_TIMESTAMP IS A DUMB DEFAULT), and looking at that issue got me to realize this bug. Fine to complete and merge #1882 and solve this afterwards I think.

MasterOdin avatar Sep 30 '20 01:09 MasterOdin