packages feed

persistent-mysql 2.3 → 2.3.0.1

raw patch · 3 files changed

+42/−14 lines, 3 files

Files

ChangeLog.md view
@@ -1,7 +1,11 @@+## 2.3.0.1++Support usign default= for changing the id field type+ ## 2.3 -* Distinguish between binary and non-binary strings in MySQL [451](https://github.com/yesodweb/persistent/pull/451)-	* Previously all string columns (VARCHAR, TEXT, etc.) were being returned from Persistent as `PersistByteString`s (i.e. as binary data). Persistent now checks character set information to determine if the value should be returned as `PersistText` or `PersistByteString`. +* Distinguish between binary and non-binary strings in MySQL [#451](https://github.com/yesodweb/persistent/pull/451)+	* Previously all string columns (VARCHAR, TEXT, etc.) were being returned from Persistent as `PersistByteString`s (i.e. as binary data). Persistent now checks character set information to determine if the value should be returned as `PersistText` or `PersistByteString`. 	* This is a **breaking change** if your code is relying on a `PersistByteString` being returned for string-like MySQL values; persistent-mysql itself had several runtime errors that needed to be fixed because of this patch. High-level code dealing purely with `PersistEntities` should be unaffected.  ## 2.2
Database/Persist/MySQL.hs view
@@ -22,6 +22,7 @@ import Control.Monad.Trans.Error (ErrorT(..)) import Control.Monad.Trans.Reader (runReaderT) import Control.Monad.Trans.Writer (runWriterT)+import Data.Monoid ((<>)) import Data.Aeson import Data.Aeson.Types (modifyFailure) import Data.ByteString (ByteString)@@ -355,7 +356,20 @@       name = entityDB entity       idtxt = case entityPrimary entity of                 Just pdef -> concat [" PRIMARY KEY (", intercalate "," $ map (escapeDBName . fieldDB) $ compositeFields pdef, ")"]-                Nothing   -> concat [escapeDBName $ fieldDB $ entityId entity, " BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY"]+                Nothing ->+                  let defText = defaultAttribute $ fieldAttrs $ entityId entity+                      sType = fieldSqlType $ entityId entity+                      autoIncrementText = case (sType, defText) of+                        (SqlInt64, Nothing) -> " AUTO_INCREMENT"+                        _ -> ""+                      maxlen = findMaxLenOfField (entityId entity)+                  in concat+                         [ escapeDBName $ fieldDB $ entityId entity+                         , " " <> showSqlType sType maxlen False+                         , " NOT NULL"+                         , autoIncrementText+                         , " PRIMARY KEY"+                         ]  -- | Find out the type of a column. findTypeOfColumn :: [EntityDef] -> DBName -> DBName -> (DBName, FieldType)@@ -375,18 +389,23 @@          ((,) col) $ do            entDef     <- find ((== name) . entityDB) allDefs            fieldDef   <- find ((== col) . fieldDB) (entityFields entDef)-           maxLenAttr <- find ((T.isPrefixOf "maxlen=") . T.toLower) (fieldAttrs fieldDef)-           readMaybe . T.unpack . T.drop 7 $ maxLenAttr+           findMaxLenOfField fieldDef --- | Helper for 'AddRefence' that finds out the 'entityId'.+-- | Find out the maxlen of a field+findMaxLenOfField :: FieldDef -> Maybe Integer+findMaxLenOfField fieldDef = do+    maxLenAttr <- find ((T.isPrefixOf "maxlen=") . T.toLower) (fieldAttrs fieldDef)+    readMaybe . T.unpack . T.drop 7 $ maxLenAttr++-- | Helper for 'AddReference' that finds out the which primary key columns to reference. addReference :: [EntityDef] -> DBName -> DBName -> DBName -> AlterColumn-addReference allDefs fkeyname reftable cname = AddReference reftable fkeyname [cname] [id_] +addReference allDefs fkeyname reftable cname = AddReference reftable fkeyname [cname] referencedColumns     where-      id_ = maybe (error $ "Could not find ID of entity " ++ show reftable-                         ++ " (allDefs = " ++ show allDefs ++ ")")-                  id $ do-                    entDef <- find ((== reftable) . entityDB) allDefs-                    return (fieldDB $ entityId entDef)+      referencedColumns = maybe (error $ "Could not find ID of entity " ++ show reftable+                                  ++ " (allDefs = " ++ show allDefs ++ ")")+                                id $ do+                                  entDef <- find ((== reftable) . entityDB) allDefs+                                  return $ map fieldDB $ entityKeyFields entDef  data AlterColumn = Change Column                  | Add' Column@@ -394,7 +413,12 @@                  | Default String                  | NoDefault                  | Update' String-                 | AddReference DBName DBName [DBName] [DBName]+                 -- | See the definition of the 'showAlter' function to see how these fields are used.+                 | AddReference+                    DBName -- ^ Referenced table+                    DBName -- ^ Foreign key name+                    [DBName] -- ^ Referencing columns+                    [DBName] -- ^ Referenced columns                  | DropReference DBName  type AlterColumn' = (DBName, AlterColumn)
persistent-mysql.cabal view
@@ -1,5 +1,5 @@ name:            persistent-mysql-version:         2.3+version:         2.3.0.1 license:         MIT license-file:    LICENSE author:          Felipe Lessa <felipe.lessa@gmail.com>, Michael Snoyman