BSD-3-Clause licensed by Matt Parsons
Maintained by parsonsmatt@gmail.com
This version can be pinned in stack with:persistent-discover-0.1.0.4@sha256:4f744e2e590e57bbaf7e9dc3cabfdfd8acc5bd5db77e2d5a7bffd65c93c621e9,3421

Module documentation for 0.1.0.4

persistent-discover

build status

Supports automatic discovery of your 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.

Changes

Changelog for persistent-discover

Unreleased changes

0.1.0.4

  • Fix a bug where non-Haskell files would be picked up and imported in the generated file. #

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 incorrect module names. #2

0.1.0.0

  • Initial Release