Since there are a lot of models in our DB, many of which operate fairly independently, we decided to define them in different modules. We then have a single migrateAll function that runs every migration in serial. It appears as though us doing this causes Persistent to not create foreign key constraints between the models, but I would really like those constraints to be there.

As a partial fix we could put them all into the same module, but we also have a separate package that depends on this first package that creates more models on top, again with some foreign keys. It would really hurt for us to have to merge those packages into one, when there is truly only a one-directional dependency between them.

Is there any way for foreign key constraints to still be created across modules? Perhaps by making it so that if you migrate a model with external foreign key constraints, the foreign model's migration is also ran. To avoid needing to order the migrations in dependency order.

It is also possible that the reason foreign keys are not being created is unrelated to this setup, but I can't seem to find anyone else running into the same issue, so I am assuming the above is the cause.

For an MCVE:

module Foo where share [mkPersist sqlSettings, mkMigrate "migrateFoo"] [persistLowerCase| Foo name String |]

module Bar where import Foo share [mkPersist sqlSettings, mkMigrate "migrateBar"] [persistLowerCase| Bar name String foo FooId |]

module Models where import Foo import Bar migrateAll :: Migration migrateAll = migrateFoo *> migrateBar