File tree Expand file tree Collapse file tree
persistent/test/Database/Persist Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ import qualified RawSqlTest
4343import qualified ReadWriteTest
4444import qualified Recursive
4545import qualified RenameTest
46+ import qualified SchemaTest
4647import qualified SumTypeTest
4748import qualified TransactionLevelTest
4849import qualified TypeLitFieldDefsTest
@@ -175,6 +176,7 @@ main = do
175176 , MigrationColumnLengthTest. migration
176177 , TransactionLevelTest. migration
177178 , LongIdentifierTest. migration
179+ , SchemaTest. migration
178180 ]
179181 PersistentTest. cleanDB
180182 ForeignKey. cleanDB
@@ -243,6 +245,7 @@ main = do
243245 MigrationTest. specsWith db
244246 LongIdentifierTest. specsWith db
245247 GeneratedColumnTestSQL. specsWith db
248+ SchemaTest. specsWith db
246249
247250 it " issue #328" $ asIO $ runSqliteInfo (mkSqliteConnectionInfo " :memory:" ) $ do
248251 void $ runMigrationSilent migrateAll
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ bug-reports: https://github.com/yesodweb/persistent/issues
1515extra-source-files : ChangeLog.md
1616
1717library
18- exposed-modules :
18+ exposed-modules :
1919 CompositeTest
2020 CustomPersistField
2121 CustomPersistFieldTest
@@ -51,6 +51,7 @@ library
5151 RenameTest
5252 Recursive
5353 SumTypeTest
54+ SchemaTest
5455 TransactionLevelTest
5556 TreeTest
5657 TypeLitFieldDefsTest
@@ -60,7 +61,7 @@ library
6061
6162 hs-source-dirs : src
6263
63- build-depends :
64+ build-depends :
6465 base >= 4.9 && < 5
6566 , aeson >= 1.0
6667 , blaze-html >= 0.9
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE UndecidableInstances #-}
2+ module SchemaTest where
3+
4+ import Init
5+ import qualified PersistentTestModels as PTM
6+
7+ share [mkPersist persistSettings, mkMigrate " migration" ] [persistLowerCase |
8+ Person schema=my_special_schema
9+ name Text
10+ age Int
11+ weight Int
12+ deriving Show Eq
13+ |]
14+
15+ cleanDB :: (MonadIO m , PersistQuery backend , PersistEntityBackend Person ~ backend ) => ReaderT backend m ()
16+ cleanDB = do
17+ deleteWhere ([] :: [Filter Person ])
18+ deleteWhere ([] :: [Filter PTM. Person ])
19+
20+ specsWith :: (MonadIO m , MonadFail m ) => RunDb SqlBackend m -> Spec
21+ specsWith runDb = describe " schema support" $ do
22+ it " insert a Person under non-default schema" $ runDb $ do
23+ insert_ $ Person " name" 1 2
24+ return ()
25+ it " insert PTM.Person and Person and check they end up in different tables" $ runDb $ do
26+ cleanDB
27+ insert_ $ Person " name" 1 2
28+ insert_ $ PTM. Person " name2" 3 Nothing
29+ schemaPersonCount <- count ([] :: [Filter Person ])
30+ ptmPersoncount <- count ([] :: [Filter PTM. Person ])
31+ -- both tables should contain only one record despite similarly named Entities
32+ schemaPersonCount + ptmPersoncount @== 2
Original file line number Diff line number Diff line change @@ -318,6 +318,7 @@ spec = describe "THSpec" $ do
318318 EntityDef
319319 { entityHaskell = EntityNameHS " HasSimpleCascadeRef"
320320 , entityDB = EntityNameDB " HasSimpleCascadeRef"
321+ , entitySchema = Nothing
321322 , entityId =
322323 EntityIdField FieldDef
323324 { fieldHaskell = FieldNameHS " Id"
You can’t perform that action at this time.
0 commit comments