groundhog-postgresql 0.4.2 → 0.4.2.2
raw patch · 4 files changed
+70/−15 lines, 4 filesdep ~groundhog
Dependency ranges changed: groundhog
Files
- Database/Groundhog/Postgresql.hs +14/−10
- Database/Groundhog/Postgresql/Array.hs +3/−3
- changelog +48/−0
- groundhog-postgresql.cabal +5/−2
Database/Groundhog/Postgresql.hs view
@@ -43,7 +43,7 @@ import Data.Int (Int64) import Data.IORef import Data.List (groupBy, intercalate, stripPrefix)-import Data.Maybe (fromJust, fromMaybe)+import Data.Maybe (fromJust, fromMaybe, isJust) import Data.Monoid import Data.Pool import Data.Time.LocalTime (localTimeToUTC, utc)@@ -95,6 +95,7 @@ getList k = getList' k instance (MonadBaseControl IO m, MonadIO m, MonadLogger m) => SchemaAnalyzer (DbPersist Postgresql m) where+ schemaExists schema = queryRaw' "SELECT 1 FROM information_schema.schemata WHERE schema_name=?" [toPrimitivePersistValue proxy schema] (fmap isJust) listTables schema = queryRaw' "SELECT table_name FROM information_schema.tables WHERE table_schema=coalesce(?,current_schema())" [toPrimitivePersistValue proxy schema] (mapAllRows $ return . fst . fromPurePersistValues proxy) listTableTriggers schema name = queryRaw' "SELECT trigger_name FROM information_schema.triggers WHERE event_object_schema=coalesce(?,current_schema()) AND event_object_table=?" [toPrimitivePersistValue proxy schema, toPrimitivePersistValue proxy name] (mapAllRows $ return . fst . fromPurePersistValues proxy) analyzeTable = analyzeTable'@@ -275,7 +276,8 @@ migrate' v = do x <- lift $ queryRaw' "SELECT current_schema()" [] id let schema = fst $ fromPurePersistValues proxy $ fromJust x- migrateRecursively (migrateEntity $ migrationPack schema) (migrateList $ migrationPack schema) v+ migPack = migrationPack schema+ migrateRecursively (migrateSchema migPack) (migrateEntity migPack) (migrateList migPack) v migrationPack :: (MonadBaseControl IO m, MonadIO m, MonadLogger m) => String -> GM.MigrationPack (DbPersist Postgresql m) migrationPack currentSchema = GM.MigrationPack@@ -434,6 +436,8 @@ fName' = maybe (error $ "showAlterDb: AddTriggerOnUpdate does not have fieldName for trigger " ++ trigName) escape fName showAlterDb (CreateOrReplaceFunction s) = Right [(False, functionPriority, s)] showAlterDb (DropFunction sch funcName) = Right [(False, functionPriority, "DROP FUNCTION " ++ withSchema sch funcName ++ "()")]+showAlterDb (CreateSchema sch ifNotExists) = Right [(False, schemaPriority, "CREATE SCHEMA " ++ ifNotExists' ++ escape sch)] where+ ifNotExists' = if ifNotExists then "IF NOT EXISTS " else "" showAlterTable :: String -> AlterTable -> [(Bool, Int, String)] showAlterTable table (AddColumn col) = [(False, defaultPriority, concat@@ -619,11 +623,12 @@ stripType = fmap reverse . stripPrefix "::" . dropWhile (\c -> isAlphaNum c || isSpace c) . reverse stripParens = stripPrefix "(" >=> fmap reverse . stripPrefix ")" . reverse -defaultPriority, referencePriority, functionPriority, triggerPriority :: Int-defaultPriority = 0-referencePriority = 1-functionPriority = 2-triggerPriority = 3+defaultPriority, schemaPriority, referencePriority, functionPriority, triggerPriority :: Int+defaultPriority = 1+schemaPriority = 0+referencePriority = 2+functionPriority = 3+triggerPriority = 4 mainTableId :: String mainTableId = "id"@@ -742,12 +747,11 @@ unBinary :: PG.Binary a -> a unBinary (PG.Binary x) = x -proxy :: Proxy Postgresql-proxy = error "Proxy Postgresql"+proxy :: proxy Postgresql+proxy = error "proxy Postgresql" withSchema :: Maybe String -> String -> String withSchema sch name = maybe "" (\x -> escape x ++ ".") sch ++ escape name- -- | Put explicit type for expression. It is useful for values which are defaulted to a wrong type. -- For example, a literal Int from a 64bit machine can be defaulted to a 32bit int by Postgresql.
Database/Groundhog/Postgresql/Array.hs view
@@ -57,8 +57,8 @@ class ArrayElem a where -- this function is added to avoid GHC bug 7126 which appears when PrimitivePersistField is added as class constraint - toElem :: DbDescriptor db => Proxy db -> a -> PersistValue - parseElem :: DbDescriptor db => Proxy db -> Parser a + toElem :: DbDescriptor db => proxy db -> a -> PersistValue + parseElem :: DbDescriptor db => proxy db -> Parser a instance ArrayElem a => ArrayElem (Array a) where toElem p (Array xs) = PersistCustom ("ARRAY[" <> query <> fromChar ']') (vals []) where @@ -121,7 +121,7 @@ doubleQuote = 34 backslash = 92 -parseArr :: (DbDescriptor db, ArrayElem a) => Proxy db -> Parser (Array a) +parseArr :: (DbDescriptor db, ArrayElem a) => proxy db -> Parser (Array a) parseArr p = Array <$> (char '{' *> parseElem p `sepBy` char ',' <* char '}') (!) :: (ExpressionOf Postgresql r a (Array elem), ExpressionOf Postgresql r b Int) => a -> b -> Expr Postgresql r elem
+ changelog view
@@ -0,0 +1,48 @@+0.4.2.2+* Create missing schemas (or databases in MySQL terminology) during migration+* Replace datatype Proxy with type variable++0.4.2+* Postgresql-specific mathematical functions (signum, quotRem)+* Geometric operators++0.4.1+* Added functions replaceBy and deleteAll+* Added type casting functions explicitType and castType++0.4.0.3+* Updated postgresql-simple dependency++0.4.0.2+* Autogenerated id is 64 bit by default+* Added createPostgresqlPool++0.4.0.1+* Exposed connection constructor++0.4.0+* Query logging+* Default column values+* Fixed postgresql-simple deprecation warnings++0.3.0.2+* Updated postgresql-simple dependency++0.3+* Switched from pool-conduit to resource-pool+* Schema qualified tables+* Support for savepoints+* Support for arrays++0.2.0+* Database indexes+* Support DB-specific column types++0.1.0.2+* Removed overly restrictive upper bound for bytestring package++0.1.0.1+* Removed overly restrictive upper bound for containers package++0.1.0+The first release.
groundhog-postgresql.cabal view
@@ -1,5 +1,5 @@ name: groundhog-postgresql-version: 0.4.2+version: 0.4.2.2 license: BSD3 license-file: LICENSE author: Boris Lykah <lykahb@gmail.com>@@ -11,6 +11,9 @@ cabal-version: >= 1.6 build-type: Simple +extra-source-files:+ changelog+ library build-depends: base >= 4 && < 5 , postgresql-simple >= 0.3 && < 0.5@@ -18,7 +21,7 @@ , bytestring >= 0.9 , blaze-builder >= 0.3.0.0 , transformers >= 0.2.1- , groundhog >= 0.4.2 && < 0.5.0+ , groundhog >= 0.4.2.2 && < 0.5.0 , monad-control >= 0.3 , monad-logger >= 0.3 , containers >= 0.2