Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/parsonsmatt/persistent-discover
Discover your Persistent Models with Ease
https://github.com/parsonsmatt/persistent-discover
Last synced: 10 days ago
JSON representation
Discover your Persistent Models with Ease
- Host: GitHub
- URL: https://github.com/parsonsmatt/persistent-discover
- Owner: parsonsmatt
- License: bsd-3-clause
- Created: 2021-05-06T18:36:52.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-04T00:30:09.000Z (about 1 year ago)
- Last Synced: 2024-04-25T18:00:43.905Z (6 months ago)
- Language: Haskell
- Size: 32.2 KB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# persistent-discover
![build status](https://github.com/parsonsmatt/persistent-discover/actions/workflows/haskell.yml/badge.svg)
Supports automatic discovery of your
[`persistent`](https://hackage.haskell.org/package/persistent) models.## As an executable
Let's say you've got a ton of `persistent` database models, all defined in a
module hierarchy like this:```
src/
Models/
Foo.hs
Bar.hs
Baz.hs
Blargh.hs
What.hs
OhNo.hs
```If you're using `persistent` to automatically generate migrations, you'll want
to have all the `[EntityDef]` in scope from each module. You can do that by
importing each module that defines models and calling `$(discoverEntities)`,
introduced in `persistent-2.13`.But you may forget to import a module.
This utility imports *all* the modules defined in the current directory and
sub-directories, and then it calls `$(discoverEntities)` for you.To use it, place the following command in a file, located in the same directory
that your Haskell modules are in:```
{-# OPTIONS_GHC -F -pgmF persistent-discover #-}
```Let's say we put that in `src/Models/All.hs`.
This generates a module `Models.All` that exports a single item: `allEntities`,
which is a `[EntityDef]` and can be used by `migrateModels` to properly perform
migrations.You'll need to add `persistent-discover` to the `build-tool-depends` on your cabal file
for this to work.