From ee8df55da3731b3c73939cb32844e6476f4cec27 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 21 Jan 2014 12:33:38 -0500 Subject: [PATCH] Add a unique xml_file_id to Injuries. --- src/TSN/XML/Injuries.hs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/TSN/XML/Injuries.hs b/src/TSN/XML/Injuries.hs index 4ef0154..6cc802f 100644 --- a/src/TSN/XML/Injuries.hs +++ b/src/TSN/XML/Injuries.hs @@ -63,6 +63,13 @@ import Xml ( pickle_unpickle, unpickleable ) + +-- +-- DB/XML Data types +-- + +-- * InjuriesTeam + -- | XML/Database representation of a team as they appear in the -- injuries documents. -- @@ -73,6 +80,8 @@ data InjuriesTeam = deriving (Data, Eq, Show, Typeable) +-- * InjuriesListing/InjuriesListingXml + -- | XML/Database representation of the injury listings. -- data InjuriesListingXml = @@ -115,6 +124,9 @@ instance FromXmlFk InjuriesListingXml where instance XmlImportFk InjuriesListingXml + +-- * Injuries/Message + -- | XML representation of an injuriesxml \. -- data Message = @@ -132,6 +144,7 @@ data Message = -- data Injuries = Injuries { + db_xml_file_id :: Int, db_sport :: String, db_time_stamp :: UTCTime } @@ -145,12 +158,17 @@ instance FromXml Message where -- from_xml Message{..} = Injuries { + db_xml_file_id = xml_xml_file_id, db_sport = xml_sport, db_time_stamp = xml_time_stamp } instance XmlImport Message +-- +-- Database code +-- + instance DbImport Message where dbmigrate _ = run_dbmigrate $ do @@ -171,6 +189,13 @@ instance DbImport Message where mkPersist tsn_codegen_config [groundhog| - entity: Injuries + constructors: + - name: Injuries + uniques: + - name: unique_injuries + type: constraint + # Prevent multiple imports of the same message. + fields: [db_xml_file_id] - entity: InjuriesListing dbName: injuries_listings @@ -192,6 +217,11 @@ mkPersist tsn_codegen_config [groundhog| |] +-- +-- XML Picklers +-- + + -- | A pickler for 'InjuriesTeam's that can convert them to/from XML. -- pickle_injuries_team :: PU InjuriesTeam @@ -204,7 +234,8 @@ pickle_injuries_team = to_tuple m = (db_team_name m, db_team_league m) --- | A pickler for 'InjuriesListingXml's that can convert them to/from XML. +-- | A pickler for 'InjuriesListingXml's that can convert them to/from +-- XML. -- pickle_listing :: PU InjuriesListingXml pickle_listing = -- 2.44.2