X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FInjuries.hs;h=3f0fea55e364b066dfe4e95a2979893f4f0e75c0;hb=4ce681700509beedf38026568ea20102801e6516;hp=af1bc377466d078e71dff41cd73da393d4840200;hpb=a0853ebe00e630b7d50f97949d4dd45c602bd454;p=dead%2Fhtsn-import.git diff --git a/src/TSN/XML/Injuries.hs b/src/TSN/XML/Injuries.hs index af1bc37..3f0fea5 100644 --- a/src/TSN/XML/Injuries.hs +++ b/src/TSN/XML/Injuries.hs @@ -3,7 +3,6 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} @@ -32,7 +31,7 @@ import Data.Time ( UTCTime ) import Data.Typeable ( Typeable ) import Database.Groundhog ( countAll, - executeRaw, + deleteAll, migrate, runMigration, silentMigrationLogger ) @@ -65,6 +64,7 @@ import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.Picklers ( xp_time_stamp ) import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) ) import Xml ( + Child(..), FromXml(..), FromXmlFk(..), ToDb(..), @@ -102,7 +102,7 @@ data InjuriesTeam = data InjuriesListingXml = InjuriesListingXml { xml_team :: InjuriesTeam, - xml_teamno :: Maybe Int, + xml_teamno :: Maybe String, -- ^ Can contain non-numerics, e.g. \"ZR2\" xml_injuries :: String, xml_updated :: Maybe Bool } deriving (Eq, Show) @@ -115,7 +115,7 @@ data InjuriesListing = InjuriesListing { db_injuries_id :: DefaultKey Injuries, db_team :: InjuriesTeam, - db_teamno :: Maybe Int, + db_teamno :: Maybe String, -- ^ Can contain non-numerics, e.g. \"ZR2\" db_injuries :: String, db_updated :: Maybe Bool } @@ -123,10 +123,11 @@ instance ToDb InjuriesListingXml where -- | The DB analogue of a 'InjuriesListingXml' is a 'InjuriesListing' type Db InjuriesListingXml = InjuriesListing -instance FromXmlFk InjuriesListingXml where +instance Child InjuriesListingXml where -- | Our foreign key points to an 'Injuries'. type Parent InjuriesListingXml = Injuries +instance FromXmlFk InjuriesListingXml where -- | To convert between a 'InjuriesListingXml' and a -- 'InjuriesListing', we simply append the foreign key. from_xml_fk fk InjuriesListingXml{..} = @@ -263,7 +264,7 @@ pickle_listing = xpElem "listing" $ xpWrap (from_tuple, to_tuple) $ xp4Tuple pickle_injuries_team - (xpOption $ xpElem "teamno" xpInt) + (xpOption $ xpElem "teamno" xpText) (xpElem "injuries" xpText) (xpOption $ xpElem "updated" xpPrim) where @@ -346,8 +347,7 @@ test_on_delete_cascade = migrate a migrate b _ <- dbimport inj - -- No idea how 'delete' works, so do this instead. - executeRaw False "DELETE FROM injuries;" [] + deleteAll a count_a <- countAll a count_b <- countAll b return $ count_a + count_b