Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Deleting mpsGeneric #1348

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion persistent-mongoDB/test/MongoInit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ _debugOn :: Bool
_debugOn = True

persistSettings :: MkPersistSettings
persistSettings = (mkPersistSettings $ ConT ''Context) { mpsGeneric = True }
persistSettings = mkPersistSettings $ ConT ''Context

dbName :: Text
dbName = "persistent"
Expand Down
2 changes: 1 addition & 1 deletion persistent-mysql/test/MyInit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ _debugOn :: Bool
_debugOn = False

persistSettings :: MkPersistSettings
persistSettings = sqlSettings { mpsGeneric = True }
persistSettings = sqlSettings

type BackendMonad = SqlBackend

Expand Down
2 changes: 1 addition & 1 deletion persistent-postgresql/test/PgInit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ dockerPg = do
_ -> Nothing

persistSettings :: MkPersistSettings
persistSettings = sqlSettings { mpsGeneric = True }
persistSettings = sqlSettings

runConn :: MonadUnliftIO m => SqlPersistT (LoggingT m) t -> m ()
runConn f = runConn_ f >>= const (return ())
Expand Down
33 changes: 11 additions & 22 deletions persistent-qq/test/PersistentTestModels.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import PersistTestPetCollarType
import PersistTestPetType

share
[ mkPersist sqlSettings { mpsGeneric = True }
[ mkPersist sqlSettings
, mkMigrate "testMigrate"
] [persistUpperCase|

Expand Down Expand Up @@ -110,10 +110,7 @@ share

|]

deriving instance Show (BackendKey backend) => Show (PetGeneric backend)
deriving instance Eq (BackendKey backend) => Eq (PetGeneric backend)

share [ mkPersist sqlSettings { mpsPrefixFields = False, mpsGeneric = True }
share [ mkPersist sqlSettings { mpsPrefixFields = False }
, mkMigrate "noPrefixMigrate"
] [persistLowerCase|
NoPrefix1
Expand All @@ -127,12 +124,6 @@ NoPrefix2
deriving Show Eq
|]

deriving instance Show (BackendKey backend) => Show (NoPrefix1Generic backend)
deriving instance Eq (BackendKey backend) => Eq (NoPrefix1Generic backend)

deriving instance Show (BackendKey backend) => Show (NoPrefix2Generic backend)
deriving instance Eq (BackendKey backend) => Eq (NoPrefix2Generic backend)

-- | Reverses the order of the fields of an entity. Used to test
-- @??@ placeholders of 'rawSql'.
newtype ReverseFieldOrder a = RFO {unRFO :: a} deriving (Eq, Show)
Expand Down Expand Up @@ -164,15 +155,13 @@ instance (PersistEntity a) => PersistEntity (ReverseFieldOrder a) where
persistIdField = error "ReverseFieldOrder.persistIdField"
fieldLens x = error "ReverseFieldOrder.fieldLens"

cleanDB
:: (MonadIO m, PersistQuery backend, PersistStoreWrite (BaseBackend backend))
=> ReaderT backend m ()
cleanDB :: (MonadIO m) => SqlPersistT m ()
cleanDB = do
deleteWhere ([] :: [Filter (PersonGeneric backend)])
deleteWhere ([] :: [Filter (Person1Generic backend)])
deleteWhere ([] :: [Filter (PetGeneric backend)])
deleteWhere ([] :: [Filter (MaybeOwnedPetGeneric backend)])
deleteWhere ([] :: [Filter (NeedsPetGeneric backend)])
deleteWhere ([] :: [Filter (OutdoorPetGeneric backend)])
deleteWhere ([] :: [Filter (UserPTGeneric backend)])
deleteWhere ([] :: [Filter (EmailPTGeneric backend)])
deleteWhere ([] :: [Filter Person])
deleteWhere ([] :: [Filter Person1])
deleteWhere ([] :: [Filter Pet])
deleteWhere ([] :: [Filter MaybeOwnedPet])
deleteWhere ([] :: [Filter NeedsPet])
deleteWhere ([] :: [Filter OutdoorPet])
deleteWhere ([] :: [Filter UserPT])
deleteWhere ([] :: [Filter EmailPT])
2 changes: 1 addition & 1 deletion persistent-sqlite/test/SqliteInit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ _debugOn :: Bool
_debugOn = False

persistSettings :: MkPersistSettings
persistSettings = sqlSettings { mpsGeneric = True }
persistSettings = sqlSettings

type BackendMonad = SqlBackend

Expand Down
3 changes: 1 addition & 2 deletions persistent-test/src/CompositeTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import Data.Maybe (isJust)
import Init


-- mpsGeneric = False is due to a bug or at least lack of a feature in mkKeyTypeDec TH.hs
share [mkPersist persistSettings { mpsGeneric = False }, mkMigrate "compositeMigrate"] [persistLowerCase|
share [mkPersist persistSettings, mkMigrate "compositeMigrate"] [persistLowerCase|
TestParent
name String maxlen=20
name2 String maxlen=20
Expand Down
4 changes: 2 additions & 2 deletions persistent-test/src/CustomPersistFieldTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ module CustomPersistFieldTest (specsWith, customFieldMigrate) where
import CustomPersistField
import Init

share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "customFieldMigrate"] [persistLowerCase|
share [mkPersist sqlSettings, mkMigrate "customFieldMigrate"] [persistLowerCase|
BlogPost
article Markdown
deriving Show Eq
|]

specsWith :: Runner backend m => RunDb backend m -> Spec
specsWith :: Runner SqlBackend m => RunDb SqlBackend m -> Spec
specsWith runDB = describe "Custom persist field" $ do
it "should read what it wrote" $ runDB $ do
let originalBlogPost = BlogPost "article"
Expand Down
3 changes: 1 addition & 2 deletions persistent-test/src/CustomPrimaryKeyReferenceTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ module CustomPrimaryKeyReferenceTest where

import Init

-- mpsGeneric = False is due to a bug or at least lack of a feature in mkKeyTypeDec TH.hs
share [mkPersist persistSettings { mpsGeneric = False }, mkMigrate "migration"] [persistLowerCase|
share [mkPersist persistSettings, mkMigrate "migration"] [persistLowerCase|
Tweet
tweetId Int
statusText Text sqltype=varchar(170)
Expand Down
14 changes: 4 additions & 10 deletions persistent-test/src/DataTypeTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ DataTypeTable no-json
utc UTCTime
|]

cleanDB'
::
( MonadIO m, PersistStoreWrite (BaseBackend backend), PersistQuery backend) => ReaderT backend m ()
cleanDB' = deleteWhere ([] :: [Filter (DataTypeTableGeneric backend)])
cleanDB' :: (MonadIO m) => SqlPersistT m ()
cleanDB' = deleteWhere ([] :: [Filter DataTypeTable])

roundFn :: RealFrac a => a -> Integer
roundFn = round
Expand Down Expand Up @@ -81,14 +79,10 @@ instance Arbitrary DataTypeTable where
specsWith
:: forall db backend m entity.
( db ~ ReaderT backend m
, PersistStoreRead backend
, backend ~ SqlBackend
, PersistEntity entity
, PersistEntityBackend entity ~ BaseBackend backend
, PersistEntityBackend entity ~ SqlBackend
, Arbitrary entity
, PersistStoreWrite backend
, PersistStoreWrite (BaseBackend backend)
, PersistQueryWrite (BaseBackend backend)
, PersistQueryWrite backend
, MonadFail m
, MonadIO m
)
Expand Down
10 changes: 5 additions & 5 deletions persistent-test/src/EmbedOrderTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Init
debug :: Show s => s -> s
debug x = trace (show x) x

share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "embedOrderMigrate"] [persistUpperCase|
share [mkPersist sqlSettings, mkMigrate "embedOrderMigrate"] [persistUpperCase|
Foo sql=foo_embed_order
bars [Bar]
deriving Eq Show
Expand All @@ -21,12 +21,12 @@ Bar sql=bar_embed_order
deriving Eq Show
|]

cleanDB :: Runner backend m => ReaderT backend m ()
cleanDB :: Runner SqlBackend m => ReaderT SqlBackend m ()
cleanDB = do
deleteWhere ([] :: [Filter (FooGeneric backend)])
deleteWhere ([] :: [Filter (BarGeneric backend)])
deleteWhere ([] :: [Filter Foo])
deleteWhere ([] :: [Filter Bar])

specsWith :: Runner backend m => RunDb backend m -> Spec
specsWith :: Runner SqlBackend m => RunDb SqlBackend m -> Spec
specsWith db = describe "embedded entities" $ do
it "preserves ordering" $ db $ do
let foo = Foo [Bar "b" "u" "g"]
Expand Down
26 changes: 13 additions & 13 deletions persistent-test/src/EmbedTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ instance PersistField a => PersistField (NonEmpty a) where
(l:ls) -> Right (l:|ls)


share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "embedMigrate"] [persistUpperCase|
share [mkPersist sqlSettings, mkMigrate "embedMigrate"] [persistUpperCase|

OnlyName
name Text
Expand Down Expand Up @@ -137,18 +137,18 @@ share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "embedMigrate"] [
|]
cleanDB :: (PersistQuery backend, PersistEntityBackend HasMap ~ backend, MonadIO m) => ReaderT backend m ()
cleanDB = do
deleteWhere ([] :: [Filter (HasEmbedGeneric backend)])
deleteWhere ([] :: [Filter (HasEmbedsGeneric backend)])
deleteWhere ([] :: [Filter (HasListEmbedGeneric backend)])
deleteWhere ([] :: [Filter (HasSetEmbedGeneric backend)])
deleteWhere ([] :: [Filter (UserGeneric backend)])
deleteWhere ([] :: [Filter (HasMapGeneric backend)])
deleteWhere ([] :: [Filter (HasListGeneric backend)])
deleteWhere ([] :: [Filter (EmbedsHasMapGeneric backend)])
deleteWhere ([] :: [Filter (ListEmbedGeneric backend)])
deleteWhere ([] :: [Filter (ARecordGeneric backend)])
deleteWhere ([] :: [Filter (AccountGeneric backend)])
deleteWhere ([] :: [Filter (HasNestedListGeneric backend)])
deleteWhere ([] :: [Filter (HasEmbed)])
deleteWhere ([] :: [Filter (HasEmbeds)])
deleteWhere ([] :: [Filter (HasListEmbed)])
deleteWhere ([] :: [Filter (HasSetEmbed)])
deleteWhere ([] :: [Filter (User)])
deleteWhere ([] :: [Filter (HasMap)])
deleteWhere ([] :: [Filter (HasList)])
deleteWhere ([] :: [Filter (EmbedsHasMap)])
deleteWhere ([] :: [Filter (ListEmbed)])
deleteWhere ([] :: [Filter (ARecord)])
deleteWhere ([] :: [Filter (Account)])
deleteWhere ([] :: [Filter (HasNestedList)])

_unlessM :: MonadIO m => IO Bool -> m () -> m ()
_unlessM predicate body = do
Expand Down
16 changes: 8 additions & 8 deletions persistent-test/src/EmptyEntityTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import Database.Persist.TH
import Init

-- Test lower case names
share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "migration"] [persistLowerCase|
share [mkPersist sqlSettings, mkMigrate "migration"] [persistLowerCase|
EmptyEntity
|]

cleanDB
::
( PersistQueryWrite backend
( PersistQueryWrite SqlBackend
, MonadIO m
, PersistStoreWrite (BaseBackend backend)
, PersistStoreWrite (BaseBackend SqlBackend)
)
=> ReaderT backend m ()
cleanDB = deleteWhere ([] :: [Filter (EmptyEntityGeneric backend)])
=> ReaderT SqlBackend m ()
cleanDB = deleteWhere ([] :: [Filter EmptyEntity])

specsWith
:: Runner backend m
=> RunDb backend m
-> Maybe (ReaderT backend m a)
:: Runner SqlBackend m
=> RunDb SqlBackend m
-> Maybe (ReaderT SqlBackend m a)
-> Spec
specsWith runConn mmigrate = describe "empty entity" $
it "inserts" $ asIO $ runConn $ do
Expand Down
2 changes: 1 addition & 1 deletion persistent-test/src/EntityEmbedTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module EntityEmbedTest where
-- this is used in EmbedTest
import Init

mkPersist persistSettings { mpsGeneric = True } [persistUpperCase|
mkPersist persistSettings [persistUpperCase|
ARecord
name Text
deriving Show Eq Read Ord
Expand Down
3 changes: 1 addition & 2 deletions persistent-test/src/ForeignKey.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import Init

import Database.Persist.EntityDef.Internal (entityExtra)

-- mpsGeneric = False is due to a bug or at least lack of a feature in mkKeyTypeDec TH.hs
share [mkPersist persistSettings { mpsGeneric = False }, mkMigrate "compositeMigrate"] [persistLowerCase|
share [mkPersist persistSettings, mkMigrate "compositeMigrate"] [persistLowerCase|
SimpleCascadeChild
ref SimpleCascadeId OnDeleteCascade
deriving Show Eq
Expand Down
12 changes: 6 additions & 6 deletions persistent-test/src/HtmlTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import Text.Blaze.Html.Renderer.Text
import Init

-- Test lower case names
share [mkPersist persistSettings { mpsGeneric = True }, mkMigrate "htmlMigrate"] [persistLowerCase|
share [mkPersist persistSettings, mkMigrate "htmlMigrate"] [persistLowerCase|
HtmlTable
html Html
deriving
|]

cleanDB :: Runner backend m => ReaderT backend m ()
cleanDB :: Runner SqlBackend m => ReaderT SqlBackend m ()
cleanDB = do
deleteWhere ([] :: [Filter (HtmlTableGeneric backend)])
deleteWhere ([] :: [Filter HtmlTable])

specsWith
:: Runner backend m
=> RunDb backend m
-> Maybe (ReaderT backend m a)
:: Runner SqlBackend m
=> RunDb SqlBackend m
-> Maybe (ReaderT SqlBackend m a)
-> Spec
specsWith runConn mmigrate = describe "html" $ do
it "works" $ asIO $ runConn $ do
Expand Down
2 changes: 1 addition & 1 deletion persistent-test/src/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ isCI = do


persistSettings :: MkPersistSettings
persistSettings = sqlSettings { mpsGeneric = True }
persistSettings = sqlSettings

instance Arbitrary PersistValue where
arbitrary = PersistInt64 `fmap` choose (0, maxBound)
Expand Down
8 changes: 4 additions & 4 deletions persistent-test/src/LargeNumberTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Data.Word

import Init

share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "numberMigrate"] [persistLowerCase|
share [mkPersist sqlSettings, mkMigrate "numberMigrate"] [persistLowerCase|
Number
intx Int
int32 Int32
Expand All @@ -16,11 +16,11 @@ share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "numberMigrate"]
|]

cleanDB
:: Runner backend m => ReaderT backend m ()
:: Runner SqlBackend m => ReaderT SqlBackend m ()
cleanDB = do
deleteWhere ([] :: [Filter (NumberGeneric backend)])
deleteWhere ([] :: [Filter Number])

specsWith :: Runner backend m => RunDb backend m -> Spec
specsWith :: Runner SqlBackend m => RunDb SqlBackend m -> Spec
specsWith runDb = describe "Large Numbers" $ do
it "preserves their values in the database" $ runDb $ do
let go x = do
Expand Down
4 changes: 2 additions & 2 deletions persistent-test/src/MaxLenTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Data.String (IsString)

import Init

share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "maxlenMigrate"] [persistLowerCase|
share [mkPersist sqlSettings, mkMigrate "maxlenMigrate"] [persistLowerCase|
MaxLen
text1 Text
text2 Text maxlen=3
Expand All @@ -24,7 +24,7 @@ share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "maxlenMigrate"]
deriving Show Eq
|]

specsWith :: Runner backend m => RunDb backend m -> Spec
specsWith :: Runner SqlBackend m => RunDb SqlBackend m -> Spec
specsWith runDb = describe "Maximum length attribute" $ do
it "truncates values that are too long" $ runDb $ do
let t1 = MaxLen a a a a a a
Expand Down
4 changes: 2 additions & 2 deletions persistent-test/src/MaybeFieldDefsTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import Data.String (IsString)

import Init

share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "maybeFieldDefMigrate"] [persistLowerCase|
share [mkPersist sqlSettings, mkMigrate "maybeFieldDefMigrate"] [persistLowerCase|
MaybeFieldDefEntity
optionalString (Maybe String)
optionalInt (Maybe Int)
deriving Eq Show
|]

specsWith :: (Runner backend m) => RunDb backend m -> Spec
specsWith :: (Runner SqlBackend m) => RunDb SqlBackend m -> Spec
specsWith runDb = describe "Maybe Field Definitions" $ do
it "runs appropriate migrations" $ runDb $ do
emptyEntity <- insert $ MaybeFieldDefEntity Nothing Nothing
Expand Down
Loading