-
Notifications
You must be signed in to change notification settings - Fork 301
Description
Sometimes you'll write a model file that has a default attr like default=FALSE and get constant no-op migration suggestions because persistent is expecting your model definition to be default=false.
In the Quasi module docs(https://hackage-content.haskell.org/package/persistent-2.16.0.0/docs/Database-Persist-Quasi.html), there is a little blurb about using \d+ in psql to get the proper value to put in default= to make these go away.
But this is not always accurate, apparently psql does a little bit of cleanup when rendering the defaults. The real way is to mimic persistent's query(
persistent/persistent-postgresql/Database/Persist/Postgresql.hs
Lines 794 to 809 in 9723907
| getColumns getter def cols = do | |
| let sqlv = T.concat | |
| [ "SELECT " | |
| , "column_name " | |
| , ",is_nullable " | |
| , ",COALESCE(domain_name, udt_name)" -- See DOMAINS below | |
| , ",column_default " | |
| , ",generation_expression " | |
| , ",numeric_precision " | |
| , ",numeric_scale " | |
| , ",character_maximum_length " | |
| , "FROM information_schema.columns " | |
| , "WHERE table_catalog=current_database() " | |
| , "AND table_schema=current_schema() " | |
| , "AND table_name=? " | |
| ] |
SELECT
column_default
FROM
information_schema.columns
WHERE
table_name='YOUR_TABLE_NAME'
AND
column_name='YOUR_COLUMN_NAME'One example is psql showing a default of now() + '120 days'::interval while persistent expects an attr of default="(now() + '120 days'::interval)".
Would be nice to mention this other query in the persistent docs.