]> gitweb.michael.orlitzky.com - dead/htsn-import.git/commitdiff
Add a unique xml_file_id to InjuriesDetail.
authorMichael Orlitzky <michael@orlitzky.com>
Tue, 21 Jan 2014 17:34:02 +0000 (12:34 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Tue, 21 Jan 2014 17:34:02 +0000 (12:34 -0500)
src/TSN/XML/InjuriesDetail.hs

index fee6ce2beb46d09da012a5ae60f9f5f37afd927a..f14b0f153d3c473c9a192f785a8b0856730379ef 100644 (file)
@@ -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