From bc54be6029dafbb7121eaeb1a2190ed1b5d87a00 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 21 Jan 2014 12:34:02 -0500 Subject: [PATCH] Add a unique xml_file_id to InjuriesDetail. --- src/TSN/XML/InjuriesDetail.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/TSN/XML/InjuriesDetail.hs b/src/TSN/XML/InjuriesDetail.hs index fee6ce2..f14b0f1 100644 --- a/src/TSN/XML/InjuriesDetail.hs +++ b/src/TSN/XML/InjuriesDetail.hs @@ -85,6 +85,7 @@ data Message = -- data InjuriesDetail = InjuriesDetail { + db_xml_file_id :: Int, db_sport :: String, db_time_stamp :: UTCTime } deriving (Eq, Show) @@ -100,6 +101,7 @@ instance FromXml Message where -- from_xml Message{..} = InjuriesDetail { + db_xml_file_id = xml_xml_file_id, db_sport = xml_sport, db_time_stamp = xml_time_stamp } @@ -112,6 +114,11 @@ instance XmlImport Message -- * InjuriesDetailListing/InjuriesDetailListingXml +-- | Database representation of an InjuriesDetailListing. It has a +-- foreign key pointing to its parent 'InjuriesDetail', and does not +-- contain the list of 'xml_player_listings' (which get their own +-- table). +-- data InjuriesDetailListing = InjuriesDetailListing { db_injuries_detail_id :: DefaultKey InjuriesDetail, @@ -133,11 +140,17 @@ data InjuriesDetailListingXml = deriving (Eq, Show) instance ToDb InjuriesDetailListingXml where + -- | The database analogue of an 'InjuriesDetailListingXml' is a + -- 'InjuriesDetailListing'. type Db InjuriesDetailListingXml = InjuriesDetailListing instance FromXmlFk InjuriesDetailListingXml where type Parent InjuriesDetailListingXml = InjuriesDetail + -- | Construct a 'InjuriesDetailListing' from a + -- 'InjuriesDetailListingXml' and a foreign key to a + -- 'InjuriesDetail'. + -- from_xml_fk fk InjuriesDetailListingXml{..} = InjuriesDetailListing { db_injuries_detail_id = fk, @@ -252,6 +265,13 @@ instance DbImport Message where mkPersist tsn_codegen_config [groundhog| - entity: InjuriesDetail dbName: injuries_detail + constructors: + - name: InjuriesDetail + uniques: + - name: unique_injuries_detail + type: constraint + # Prevent multiple imports of the same message. + fields: [db_xml_file_id] - entity: InjuriesDetailListing dbName: injuries_detail_listings -- 2.44.2