leafo / lapis

A web framework for Lua and OpenResty written in MoonScript
http://leafo.net/lapis/
MIT License
3.12k stars 247 forks source link

Postgresql how to add default value current_date #765

Closed ropoko closed 7 months ago

ropoko commented 1 year ago

On migrations, when I try to add the default value current_date on a column with type date, I got this error:

ERROR: invalid input syntax for type date: "current_date" (127)

And here is how I tried:

schema.create_table('rules', {
        ...
    { 'created_at', types.date({ default='current_date' }) },
})

The error here is that lapis created this SQL:

...
"created_at" date NOT NULL DEFAULT 'current_date'

and the current_date should not be in quotes.

leafo commented 7 months ago

You can use default = db.raw("current_date") to insert a SQL fragment directly as the default, otherwise it's treated as a string literal