persistent-mysql 2.13.0.2 → 2.13.0.3
raw patch · 3 files changed
+38/−15 lines, 3 files
Files
- ChangeLog.md +7/−0
- Database/Persist/MySQL.hs +30/−14
- persistent-mysql.cabal +1/−1
ChangeLog.md view
@@ -1,5 +1,12 @@ # Changelog for persistent-mysql +## 2.13.0.3++* Bugfix: Omit `REFERENCES` in `CREATe TABLE` statements. These are ignored by+ MySQL, but are a syntax error for MariaDB.+ [#1355](https://github.com/yesodweb/persistent/pull/1355), a continuation of+ [#1283](https://github.com/yesodweb/persistent/pull/1283)+ ## 2.13.0.2 * Bugfix: prevent fetching constraint info from other databases during migrations [#1301](https://github.com/yesodweb/persistent/pull/1301)
Database/Persist/MySQL.hs view
@@ -46,7 +46,6 @@ import Control.Monad.Trans.Reader (ReaderT, runReaderT) import Control.Monad.Trans.Writer (runWriterT) -import qualified Data.List.NonEmpty as NEL import Data.Acquire (Acquire, mkAcquire, with) import Data.Aeson import Data.Aeson.Types (modifyFailure)@@ -59,6 +58,7 @@ import Data.IORef import Data.Int (Int64) import Data.List (find, groupBy, intercalate, sort)+import qualified Data.List.NonEmpty as NEL import qualified Data.Map as Map import Data.Maybe (fromMaybe, listToMaybe, mapMaybe) import Data.Monoid ((<>))@@ -72,9 +72,9 @@ import System.Environment (getEnvironment) import Database.Persist.Sql-import Database.Persist.SqlBackend import Database.Persist.Sql.Types.Internal (makeIsolationLevelStatement) import qualified Database.Persist.Sql.Util as Util+import Database.Persist.SqlBackend import qualified Database.MySQL.Base as MySQLBase import qualified Database.MySQL.Base.Types as MySQLBase@@ -453,7 +453,7 @@ , "(" , idtxt , if null nonIdCols then [] else ","- , intercalate "," $ map showColumn nonIdCols+ , intercalate "," $ map showCreateColumn nonIdCols , ")" ] where@@ -467,7 +467,9 @@ concat [ " PRIMARY KEY (" , intercalate ","- $ map (escapeF . fieldDB) $ NEL.toList $ compositeFields pdef+ $ map (escapeF . fieldDB)+ $ NEL.toList+ $ compositeFields pdef , ")" ] EntityIdField idField ->@@ -961,8 +963,14 @@ -- | Prints the part of a @CREATE TABLE@ statement about a given -- column.-showColumn :: Column -> String-showColumn (Column n nu t def gen _defConstraintName maxLen ref) = concat+showCreateColumn :: Column -> String+showCreateColumn = showColumn False++showAlterColumn :: Column -> String+showAlterColumn = showColumn True++showColumn :: Bool -> Column -> String+showColumn showReferences (Column n nu t def gen _defConstraintName maxLen ref) = concat [ escapeF n , " " , showSqlType t maxLen True@@ -975,13 +983,21 @@ , if nu then "NULL" else "NOT NULL" , case def of Nothing -> ""- Just s -> -- Avoid DEFAULT NULL, since it is always unnecessary, and is an error for text/blob fields- if T.toUpper s == "NULL" then ""- else " DEFAULT " ++ T.unpack s+ Just s ->+ -- Avoid DEFAULT NULL, since it is always unnecessary, and is an error for text/blob fields+ if T.toUpper s == "NULL"+ then ""+ else " DEFAULT " ++ T.unpack s , case ref of- Nothing -> ""- Just cRef -> " REFERENCES " ++ escapeE (crTableName cRef)- <> " " <> T.unpack (renderFieldCascade (crFieldCascade cRef))+ Just cRef | showReferences ->+ mconcat+ [ " REFERENCES "+ , escapeE (crTableName cRef)+ , " "+ , T.unpack (renderFieldCascade (crFieldCascade cRef))+ ]+ _ ->+ "" ] @@ -1050,14 +1066,14 @@ , " CHANGE " , escapeF n , " "- , showColumn (Column n nu t def gen defConstraintName maxLen Nothing)+ , showAlterColumn (Column n nu t def gen defConstraintName maxLen Nothing) ] showAlter table (Add' col) = concat [ "ALTER TABLE " , escapeE table , " ADD COLUMN "- , showColumn col+ , showAlterColumn col ] showAlter table (Drop c) = concat
persistent-mysql.cabal view
@@ -1,5 +1,5 @@ name: persistent-mysql-version: 2.13.0.2+version: 2.13.0.3 license: MIT license-file: LICENSE author: Felipe Lessa <felipe.lessa@gmail.com>, Michael Snoyman