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

Deprecate sum-type tables #1385

Merged
merged 4 commits into from
Apr 12, 2022
Merged
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
6 changes: 5 additions & 1 deletion persistent/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog for persistent


## 2.14.0.0 (unreleased)

* [#1386](https://github.com/yesodweb/persistent/pull/1386)
Expand All @@ -9,6 +10,10 @@
instead.
* Remove the `CompositeDef` constructor from `ReferenceDef` which was not
used internally anymore.
* [#1385](https://github.com/yesodweb/persistent/pull/1385)
* The support for entity-level sum types is deprecated. It adds a
considerable amount of complexity to the code, and the pattern is not
particularly good for actually supporting sum types in most databases.
* [#1384](https://github.com/yesodweb/persistent/pull/1384)
* Add `tabulateEntityA` to the `PersistEntity` class, allowing you to
construct an `Entity a` by providing a function `EntityField a t -> f t`.
Expand All @@ -21,7 +26,6 @@
* [#1374](https://github.com/yesodweb/persistent/pull/1374)
* Increasing test coverage for errors thrown when parsing entity definitions


## 2.13.3.4

* [#1379](https://github.com/yesodweb/persistent/pull/1379)
Expand Down
2 changes: 2 additions & 0 deletions persistent/Database/Persist/Quasi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ import Employment as Import

=== Entity-level

NOTE: This feature is deprecated as of version 2.14 and will be removed in 2.15 (unless there are many complaints).

The
<https://github.com/yesodweb/persistent/blob/master/persistent-test/src/SumTypeTest.hs#L35 tests for this feature>
demonstrate their usage. Note the use of the sign @+@ in front of the entity
Expand Down
9 changes: 9 additions & 0 deletions persistent/Database/Persist/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,15 @@ fieldError tableName fieldName err = mconcat

mkEntity :: M.Map EntityNameHS a -> EntityMap -> MkPersistSettings -> UnboundEntityDef -> Q [Dec]
mkEntity embedEntityMap entityMap mps preDef = do
when (isEntitySum (unboundEntityDef preDef)) $ do
reportWarning $ unlines
[ "persistent has deprecated sum type entities as of 2.14.0.0."
, "We will delete support for these entities in 2.15.0.0."
, "If you need these, please add a comment on this GitHub issue:"
, ""
, " https://github.com/yesodweb/persistent/issues/987"
]

entityDefExp <- liftAndFixKeys mps embedEntityMap entityMap preDef
let
entDef =
Expand Down
43 changes: 43 additions & 0 deletions persistent/test/Database/Persist/TH/SumSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

module Database.Persist.TH.SumSpec where

import TemplateTestImports


import Database.Persist.TH.MultiBlockSpec.Model

share
[ mkPersistWith sqlSettings importDefList
]
[persistLowerCase|

What
name Text

Lamp
name Text

+Please
what WhatId
lamp LampId
|]

spec :: Spec
spec = do
it "should warn" True

2 changes: 2 additions & 0 deletions persistent/test/Database/Persist/THSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import qualified Database.Persist.TH.RequireOnlyPersistImportSpec as RequireOnly
import qualified Database.Persist.TH.SharedPrimaryKeyImportedSpec as SharedPrimaryKeyImportedSpec
import qualified Database.Persist.TH.SharedPrimaryKeySpec as SharedPrimaryKeySpec
import qualified Database.Persist.TH.ToFromPersistValuesSpec as ToFromPersistValuesSpec
import qualified Database.Persist.TH.SumSpec as SumSpec

-- test to ensure we can have types ending in Id that don't trash the TH
-- machinery
Expand Down Expand Up @@ -177,6 +178,7 @@ instance Arbitrary Address where

spec :: Spec
spec = describe "THSpec" $ do
describe "SumSpec" $ SumSpec.spec
PersistWithSpec.spec
KindEntitiesSpec.spec
NestedSymbolsInTypeSpec.spec
Expand Down