{-# LANGUAGE CPP #-}
module Database.Persist.Discover
( findPersistentModelFiles
) where
import Database.Persist.Discover.Exe (getFilesRecursive, stripSuffix)
import Language.Haskell.TH
import Language.Haskell.TH.Syntax hiding (makeRelativeToProject)
import Data.FileEmbed
findPersistentModelFiles
:: FilePath
-> Q (TExp [FilePath])
findPersistentModelFiles :: FilePath -> Q (TExp [FilePath])
findPersistentModelFiles FilePath
root = do
FilePath
projectRoot <- FilePath -> Q FilePath
makeRelativeToProject FilePath
root
[FilePath]
files <- forall a. IO a -> Q a
runIO forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter FilePath -> Bool
isPersistentModelFile forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> IO [FilePath]
getFilesRecursive FilePath
projectRoot
#if MIN_VERSION_template_haskell(2,17,0)
forall (m :: * -> *) a. Code m a -> m (TExp a)
examineCode forall a b. (a -> b) -> a -> b
$ forall t (m :: * -> *). (Lift t, Quote m) => t -> Code m t
liftTyped [FilePath]
files
#else
liftTyped files
#endif
where
isPersistentModelFile :: FilePath -> Bool
isPersistentModelFile FilePath
filename =
case forall a. Eq a => [a] -> [a] -> Maybe [a]
stripSuffix FilePath
".persistentmodels" FilePath
filename of
Just FilePath
_ ->
Bool
True
Maybe FilePath
_ ->
Bool
False