dbmigrations-postgresql (empty) → 2.0.0
raw patch · 5 files changed
+200/−0 lines, 5 filesdep +HDBCdep +HDBC-postgresqldep +HUnitsetup-changed
Dependencies added: HDBC, HDBC-postgresql, HUnit, base, dbmigrations, process
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- dbmigrations-postgresql.cabal +65/−0
- programs/MooPostgreSQL.hs +28/−0
- test/TestDriver.hs +75/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2009, Jonathan Daugherty.+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * The names of the contributors may not be used to endorse or+ promote products derived from this software without specific+ prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ dbmigrations-postgresql.cabal view
@@ -0,0 +1,65 @@+Name: dbmigrations-postgresql+Version: 2.0.0+Synopsis: The dbmigrations tool built for PostgreSQL databases+Description: This package contains the executable to work with+ the dbmigrations package when the database backend+ is PostgreSQL. See the package dbmigrations for details+ about the dbmigrations project in general.++ To get started, see the 'README.md'+ (https://github.com/jtdaugherty/dbmigrations/blob/master/README.md)+ and 'MOO.TXT'+ (https://github.com/jtdaugherty/dbmigrations/blob/master/MOO.TXT)+ files included in the dbmigrations package and the+ usage output for the 'moo-postgresql' command.++Category: Database+Author: Jonathan Daugherty <cygnus@foobox.com>+Maintainer: Jonathan Daugherty <cygnus@foobox.com>+Build-Type: Simple+License: BSD3+License-File: LICENSE+Cabal-Version: >= 1.10++Source-Repository head+ type: git+ location: git://github.com/jtdaugherty/dbmigrations-postgresql.git++Executable moo-postgresql+ default-language: Haskell2010+ Build-Depends:+ base >= 4 && < 5,+ dbmigrations >= 2,+ HDBC-postgresql++ if impl(ghc >= 6.12.0)+ ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields+ -fno-warn-unused-do-bind+ else+ ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields++ Hs-Source-Dirs: programs+ Main-is: MooPostgreSQL.hs++test-suite dbmigrations-postgresql-tests+ default-language: Haskell2010+ type: exitcode-stdio-1.0+ Build-Depends:+ base >= 4 && < 5,+ dbmigrations >= 2,+ HDBC >= 2.2.1,+ HDBC-postgresql == 2.3.2.4,+ process >= 1.1,+ HUnit >= 1.2++ other-modules:+ TestDriver++ if impl(ghc >= 6.12.0)+ ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields+ -fno-warn-unused-do-bind -Wwarn+ else+ ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields++ Hs-Source-Dirs: test+ Main-is: TestDriver.hs
+ programs/MooPostgreSQL.hs view
@@ -0,0 +1,28 @@+module Main+ ( main+ )+where++import Database.HDBC.PostgreSQL (connectPostgreSQL)+import Prelude hiding (lookup)+import System.Environment (getArgs)+import System.Exit++import Database.Schema.Migrations.Backend.HDBC (hdbcBackend)+import Moo.Core+import Moo.Main++main :: IO ()+main = do+ args <- getArgs+ (_, opts, _) <- procArgs args+ loadedConf <- loadConfiguration $ _configFilePath opts+ case loadedConf of+ Left e -> putStrLn e >> exitFailure+ Right conf -> do+ let connectionString = _connectionString conf+ connection <- connectPostgreSQL connectionString+ let backend = hdbcBackend connection+ parameters = makeParameters conf backend+ mainWithParameters args parameters+
+ test/TestDriver.hs view
@@ -0,0 +1,75 @@+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE ScopedTypeVariables #-}+module Main where++import Database.Schema.Migrations.Backend.HDBC (hdbcBackend)+import Database.Schema.Migrations.Test.BackendTest as BackendTest++import Control.Exception (catch, catches, finally, Handler(..), SomeException )+import Database.HDBC ( IConnection(disconnect) )+import qualified Database.HDBC as HDBC+import qualified Database.HDBC.PostgreSQL as PostgreSQL+import System.Exit+import System.IO ( stderr )+import System.Process ( system )+import Test.HUnit++data PostgreSQLBackendConnection =+ forall a. HDBC.IConnection a => HDBCConnection a++instance BackendConnection PostgreSQLBackendConnection where+ supportsTransactionalDDL = const True+ makeBackend (HDBCConnection c) = hdbcBackend c+ commit (HDBCConnection c) = HDBC.commit c+ withTransaction (HDBCConnection c) transaction =+ HDBC.withTransaction c (transaction . HDBCConnection)+ getTables (HDBCConnection c) = HDBC.getTables c+ catchAll (HDBCConnection _) act handler =+ act `catches` [ Handler (\(_ :: HDBC.SqlError) -> handler) ]+++loadTests :: IO [Test]+loadTests = do++ pgConn <- setupPostgresDb++ let backendConnection :: PostgreSQLBackendConnection = HDBCConnection pgConn+ testAct = (BackendTest.tests backendConnection)+ `finally`+ (disconnect pgConn >> teardownPostgresDb)+ return [ ("PostgreSQL backend tests") ~: test testAct ]++tempDatabase :: String+tempDatabase = "dbmigrations_test"++ignoreException :: SomeException -> IO ()+ignoreException _ = return ()++setupPostgresDb :: IO PostgreSQL.Connection+setupPostgresDb = do+ teardownPostgresDb `catch` ignoreException++ -- create database+ status <- system $ "createdb " ++ tempDatabase+ case status of+ ExitSuccess -> return ()+ ExitFailure _ -> error $ "Failed to create PostgreSQL database " ++ (show tempDatabase)++ -- return test db connection+ PostgreSQL.connectPostgreSQL $ "dbname=" ++ tempDatabase++teardownPostgresDb :: IO ()+teardownPostgresDb = do+ -- drop database+ status <- system $ "dropdb " ++ tempDatabase ++ " 2>/dev/null"+ case status of+ ExitSuccess -> return ()+ ExitFailure _ -> error $ "Failed to drop PostgreSQL database " ++ (show tempDatabase)++main :: IO ()+main = do+ tests_ <- loadTests+ (testResults, _) <- runTestText (putTextToHandle stderr False) $ test tests_+ if errors testResults + failures testResults > 0+ then exitFailure+ else exitSuccess