Skip to content

Commit a13c912

Browse files
committed
hell yeah
1 parent 59e7d00 commit a13c912

File tree

1 file changed

+17
-1
lines changed
  • persistent-postgresql/Database/Persist/Postgresql/Internal

1 file changed

+17
-1
lines changed

persistent-postgresql/Database/Persist/Postgresql/Internal/Migration.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ migrateEntityFromSchemaState schemaState allDefs entity =
537537
allDefs
538538
entity
539539
(newcols, udspair)
540-
(essColumns, Map.toList essConstraints)
540+
(map dubiouslyRemoveReferences essColumns, Map.toList essConstraints)
541541
acs' = map (AlterColumn name) acs
542542
ats' = map (AlterTable name) ats
543543
in
@@ -558,6 +558,22 @@ migrateEntityFromSchemaState schemaState allDefs entity =
558558
newcols
559559
foreignsAlt = mapMaybe (mkForeignAlt entity) fdefs
560560

561+
-- HACK! This shouldn't really be here; it was added to preserve existing
562+
-- behaviour. The migrator currently expects to only see cReference set in
563+
-- the old columns if it is also set in the new ones. This means that the
564+
-- migrator sometimes behaves incorrectly for standalone Foreign
565+
-- declarations, like Child in the ForeignKey test in persistent-test.
566+
--
567+
-- See https://github.com/yesodweb/persistent/issues/1611#issuecomment-3613251095 for
568+
-- more info
569+
dubiouslyRemoveReferences oldCol =
570+
case List.find (\c -> cName c == cName oldCol) newcols of
571+
Just new | isNothing (cReference new) ->
572+
oldCol { cReference = Nothing }
573+
_ ->
574+
-- otherwise no-op, `getAlters` will handle dropping this for us.
575+
oldCol
576+
561577
-- | Indicates whether a Postgres Column is safe to drop.
562578
--
563579
-- @since 2.17.1.0

0 commit comments

Comments
 (0)