persistent-discover: Persistent module discover utilities

[ bsd3, library, program, web ] [ Propose Tags ]

This package provides an executable for discovering Persistent model definition files, as well as a library function to glob all persistent model files. Please see the README on GitHub at https://github.com/parsonsmatt/persistent-discover#readme


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.0.7
Change log ChangeLog.md
Dependencies base (>=4.12 && <5), directory, dlist, file-embed, filepath, mtl, persistent (>=2.13.0.0), persistent-discover, template-haskell (>=2.16.0.0 && <2.19) [details]
License BSD-3-Clause
Copyright Matt Parsons
Author Matt Parsons
Maintainer parsonsmatt@gmail.com
Revised Revision 1 made by parsonsmatt at 2022-08-22T23:49:29Z
Category Web
Home page https://github.com/parsonsmatt/persistent-discover#readme
Bug tracker https://github.com/parsonsmatt/persistent-discover/issues
Source repo head: git clone https://github.com/parsonsmatt/persistent-discover
Uploaded by parsonsmatt at 2021-06-30T23:28:26Z
Distributions LTSHaskell:0.1.0.7, NixOS:0.1.0.7, Stackage:0.1.0.7
Executables persistent-discover
Downloads 960 total (28 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2021-07-01 [all 1 reports]

Readme for persistent-discover-0.1.0.4

[back to package description]

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.