persistent-discover
Persistent module discover utilities
https://github.com/parsonsmatt/persistent-discover#readme
LTS Haskell 23.27: | 0.1.0.7 |
Stackage Nightly 2025-07-12: | 0.1.0.7 |
Latest on Hackage: | 0.1.0.7 |
persistent-discover-0.1.0.7@sha256:9a872b4be4fb5b965cb3b0f7a4f376f130d2bc14aa4aae5961824381226885ba,3646
Module documentation for 0.1.0.7
- Database
- Database.Persist
persistent-discover
Supports automatic discovery of yourpersistent
models.
As an executable
Let’s say you’ve got a ton ofpersistent
database models, all defined in amodule hierarchy like this:
src/ Models/ Foo.hs Bar.hs Baz.hs Blargh.hs What.hs OhNo.hs
If you’re usingpersistent
to automatically generate migrations, you’ll wantto have all the[EntityDef]
in scope from each module. You can do that byimporting each module that defines models and calling$(discoverEntities)
,introduced inpersistent-2.13
.
But you may forget to import a module.
This utility importsall the modules defined in the current directory andsub-directories, and then it calls$(discoverEntities)
for you.
To use it, place the following command in a file, located in the same directorythat your Haskell modules are in:
{-# OPTIONS_GHC -F -pgmF persistent-discover #-}
Let’s say we put that insrc/Models/All.hs
.This generates a moduleModels.All
that exports a single item:allEntities
,which is a[EntityDef]
and can be used bymigrateModels
to properly performmigrations.
You’ll need to addpersistent-discover
to thebuild-tool-depends
on your cabal filefor this to work.
Changes
Changelog for persistent-discover
Unreleased changes
0.1.0.7
- Support mtl-2.3#9
0.1.0.6
- Support GHC 9.4#7
0.1.0.5
- Fix a bug where
TemplateHaskell
pragma was not added.#6
0.1.0.4
- Fix a bug where non-Haskell files would be picked up and imported in thegenerated file.#4
0.1.0.3
- Remove embarrasing lib module.
0.1.0.2
- Support GHC 9#3
0.1.0.1
- Fix behavior where uppercase directories (eg on Mac OS) would cause incorrectmodule names.#2
0.1.0.0
- Initial Release