1 -- | Definition of the DbImport typeclass.
10 import Control.Monad.IO.Class ( MonadIO )
11 import Database.Groundhog (
13 import Database.Groundhog.Core ( Migration, PersistBackend )
14 import Network.Services.TSN.Report ( report_info )
17 import TSN.XmlImport ( XmlImport(..) )
20 -- | The type that will be returned from every file import attempt.
23 ImportFailed String -- ^ Failure with an error message.
25 | ImportSkipped String -- ^ We processed the file, but didn't import it.
26 -- The reason is contained in the second field.
28 | ImportSucceeded -- ^ We did import records.
30 | ImportUnsupported String -- ^ We didn't know how to process this file.
31 -- The second field should contain info.
34 -- | Instances of this type know how to insert themselves into a
35 -- Groundhog database.
37 class DbImport a where
38 -- | Import an instance of type @a@.
39 dbimport :: (PersistBackend m) => a -> m ImportResult
41 -- | This must migrate *all* stuffs that can potentially be
42 -- created/used by the type @a@.
43 dbmigrate :: (MonadIO m, PersistBackend m) => a -> m ()
46 -- | The simplest possible implementation of 'dbimport', for types
47 -- which happen to be members of the XmlImport typeclass.
49 dbimport_generic :: (XmlImport a, MonadIO m, PersistBackend m)
52 dbimport_generic x = insert_xml x >> return ImportSucceeded
55 -- | A migration runner that will use our normal info reporting
57 run_dbmigrate :: (MonadIO m, PersistBackend m) => Migration m -> m ()
59 runMigration pretty_migration_logger
61 pretty_migration_logger x =
62 report_info ("Migration: " ++ x ++ ";")