yesodweb / persistent

Persistence interface for Haskell allowing multiple storage methods.
MIT License
459 stars 293 forks source link

In persistent-postgresql defining the sqltype of a field as "timestamp without time zone" causes remigrations #514

Open nmk opened 8 years ago

nmk commented 8 years ago

When using persistent with PostgreSQL and having the following definition

createdAt UTCTime "sqltype=timestamp without time zone" default=now()

causes a

Migrating: ALTER TABLE "memberships" ALTER COLUMN "created_at" TYPE timestamp without time zone

every time the migrations are run. The type of the field in the DB is set correctly the first time, I would expect it not to issue an ALTER statement every time.

Is this a (quoting?) problem with my field definition or is persistent not getting the correct column type when calculating the necessary migrations?

snoyberg commented 8 years ago

This is likely a quoting or capitalization problem. Two ways of debugging this are:

nmk commented 8 years ago

It turns out in PostgreSQL timestamp and timestamp without time zone are synonyms and the udt_name of such a column is reported simply as timestamp, see first note on http://www.postgresql.org/docs/current/static/datatype-datetime.html. So one option is to define the sqltype= as timestamp, the other is to add an alias in sqlShowType such as

showSqlType (SqlOther (T.toLower -> "timestamp")) = "TIMESTAMP WITHOUT TIME ZONE"

in Database.Persist.Postgresql.

snoyberg commented 8 years ago

The latter seems like it could cause problems for people using timestamp right now. I'd recommend changing your schema to use timestamp instead.

On Wed, Dec 9, 2015, 12:50 PM Nickolay Kolev notifications@github.com wrote:

It turns out in PostgreSQL timestamp and timestamp without time zone are synonyms and the udt_name of such a column is reported simply as timestamp, see first note on http://www.postgresql.org/docs/current/static/datatype-datetime.html. So one option is to define the sqltype= as timestamp, the other is to add an alias in sqlShowType such as

showSqlType (SqlOther (T.toLower -> "timestamp")) = "TIMESTAMP WITHOUT TIME ZONE"

in Database.Persist.Postgresql.

— Reply to this email directly or view it on GitHub https://github.com/yesodweb/persistent/issues/514#issuecomment-163187026 .