2. Write a test for test/xml/Odds_XML-long-import.xml once it no
longer takes 10 minutes to import (Postgres only?).
-3. Write a test for the ON DELETE CASCADE behavior (newsxml, Odds_XML,
- weatherxml).
+3. Write a test for the ON DELETE CASCADE behavior (Odds_XML, weatherxml).
+
+4. Add support the the second type of weatherxml (see man page).
import Data.Tuple.Curry ( uncurryN )
import Data.Typeable ( Typeable )
import Database.Groundhog (
+ countAll,
+ executeRaw,
insert_,
- migrate )
+ migrate,
+ runMigration,
+ silentMigrationLogger )
import Database.Groundhog.Core ( DefaultKey )
+import Database.Groundhog.Generic ( runDbConn )
+import Database.Groundhog.Sqlite ( withSqliteConn )
import Database.Groundhog.TH (
defaultCodegenConfig,
groundhog,
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
import TSN.Picklers ( xp_time_stamp )
import TSN.XmlImport ( XmlImport(..) )
-import Xml ( FromXml(..), ToDb(..), pickle_unpickle, unpickleable )
+import Xml (
+ FromXml(..),
+ ToDb(..),
+ pickle_unpickle,
+ unpickleable,
+ unsafe_unpickle )
--
testGroup
"News tests"
[ test_news_fields_have_correct_names,
+ test_on_delete_cascade,
test_pickle_of_unpickle_is_identity,
test_unpickle_succeeds ]
actual <- unpickleable path pickle_message
let expected = True
actual @?= expected
+
+
+-- | Make sure everything gets deleted when we delete the top-level
+-- record.
+--
+test_on_delete_cascade :: TestTree
+test_on_delete_cascade = testGroup "cascading delete tests"
+ [ check "deleting news deletes its children"
+ "test/xml/newsxml.xml" ]
+ where
+ check desc path = testCase desc $ do
+ news <- unsafe_unpickle path pickle_message
+ let a = undefined :: News
+ let b = undefined :: NewsTeam
+ let c = undefined :: News_NewsTeam
+ let d = undefined :: NewsLocation
+ let e = undefined :: News_NewsLocation
+ actual <- withSqliteConn ":memory:" $ runDbConn $ do
+ runMigration silentMigrationLogger $ do
+ migrate a
+ migrate b
+ migrate c
+ migrate d
+ migrate e
+ _ <- dbimport news
+ -- No idea how 'delete' works, so do this instead.
+ executeRaw False "DELETE FROM news;" []
+ count_a <- countAll a
+ count_b <- countAll b
+ count_c <- countAll c
+ count_d <- countAll d
+ count_e <- countAll e
+ return $ count_a + count_b + count_c + count_d + count_e
+ -- There are 2 news_teams and 2 news_locations that should remain.
+ let expected = 4
+ actual @?= expected