diff --git a/persistent-postgresql/Database/Persist/Postgresql.hs b/persistent-postgresql/Database/Persist/Postgresql.hs index 056e6391a..dc97abdbc 100644 --- a/persistent-postgresql/Database/Persist/Postgresql.hs +++ b/persistent-postgresql/Database/Persist/Postgresql.hs @@ -1103,7 +1103,15 @@ getColumn _ _ columnName _ = -- | Intelligent comparison of SQL types, to account for SqlInt32 vs SqlOther integer sqlTypeEq :: SqlType -> SqlType -> Bool sqlTypeEq x y = - T.toCaseFold (showSqlType x) == T.toCaseFold (showSqlType y) + let + -- Non exhaustive helper to map postgres aliases to the same name. Based on + -- https://www.postgresql.org/docs/9.5/datatype.html. + -- This prevents needless `ALTER TYPE`s when the type is the same. + normalize "int8" = "bigint" + normalize "serial8" = "bigserial" + normalize v = v + in + normalize (T.toCaseFold (showSqlType x)) == normalize (T.toCaseFold (showSqlType y)) findAlters :: [EntityDef] diff --git a/persistent-postgresql/test/EquivalentTypeTestPostgres.hs b/persistent-postgresql/test/EquivalentTypeTestPostgres.hs index 51b21930c..b23c3606a 100644 --- a/persistent-postgresql/test/EquivalentTypeTestPostgres.hs +++ b/persistent-postgresql/test/EquivalentTypeTestPostgres.hs @@ -21,7 +21,7 @@ import PgInit share [mkPersist sqlSettings, mkMigrate "migrateAll1"] [persistLowerCase| EquivalentType sql=equivalent_types - field1 Int + field1 Int sqltype=bigint field2 T.Text sqltype=text field3 T.Text sqltype=us_postal_code deriving Eq Show @@ -29,7 +29,7 @@ EquivalentType sql=equivalent_types share [mkPersist sqlSettings, mkMigrate "migrateAll2"] [persistLowerCase| EquivalentType2 sql=equivalent_types - field1 Int + field1 Int sqltype=int8 field2 T.Text field3 T.Text sqltype=us_postal_code deriving Eq Show diff --git a/persistent/ChangeLog.md b/persistent/ChangeLog.md index d92f06331..107e405a1 100644 --- a/persistent/ChangeLog.md +++ b/persistent/ChangeLog.md @@ -1,4 +1,9 @@ -# Changelog for persistent +# Changelog for persistentChan + +## 2.14.6.1 (unreleased) + +* [#1518](https://github.com/yesodweb/persistent/pull/1518) + * Normalize postgres type aliases to prevent noop migrations ## 2.14.6.0