From 4a679f3e54f5cd1a990a8151b95fcb9861861477 Mon Sep 17 00:00:00 2001 From: artik008 Date: Thu, 6 Jun 2019 15:40:41 +0300 Subject: [PATCH 1/2] Update to LTS-13.24 --- dbmigrations.cabal | 6 +- .../Schema/Migrations/Backend/Hasql.hs | 67 ++++++++++++------- stack.yaml | 4 +- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/dbmigrations.cabal b/dbmigrations.cabal index 1eb14a1..bcaf447 100644 --- a/dbmigrations.cabal +++ b/dbmigrations.cabal @@ -70,7 +70,7 @@ Library Build-Depends: base >= 4 && < 5, - hasql == 1.1.1, + hasql, time >= 1.4, random >= 1.0, containers >= 0.2, @@ -122,7 +122,7 @@ test-suite dbmigrations-tests yaml-light >= 0.1, bytestring >= 0.9, MissingH, - hasql == 1.1.1, + hasql, HUnit >= 1.2, process >= 1.1, configurator >= 0.2, @@ -159,7 +159,7 @@ Executable moo base >= 4 && < 5, configurator >= 0.2, dbmigrations, - hasql == 1.1.1, + hasql, bytestring if impl(ghc >= 6.12.0) diff --git a/src/Database/Schema/Migrations/Backend/Hasql.hs b/src/Database/Schema/Migrations/Backend/Hasql.hs index 9b9d5e3..ba0ee32 100644 --- a/src/Database/Schema/Migrations/Backend/Hasql.hs +++ b/src/Database/Schema/Migrations/Backend/Hasql.hs @@ -4,25 +4,22 @@ module Database.Schema.Migrations.Backend.Hasql ) where -import Hasql.Session -import Hasql.Query (statement) -import qualified Hasql.Encoders as H.Encode -import Hasql.Decoders -import Hasql.Connection +import Hasql.Connection +import Hasql.Decoders +import qualified Hasql.Encoders as H.Encode +import Hasql.Session +import Hasql.Statement -import Database.Schema.Migrations.Backend - ( Backend(..) - , rootMigrationName - ) -import Database.Schema.Migrations.Migration - ( Migration(..) - , newMigration - ) +import Database.Schema.Migrations.Backend (Backend (..), + rootMigrationName) +import Database.Schema.Migrations.Migration (Migration (..), + newMigration) -import Data.ByteString (ByteString) -import Data.Monoid ( (<>) ) -import Data.Time.Clock (getCurrentTime) -import System.Exit (ExitCode (ExitFailure), exitWith) +import Data.ByteString (ByteString) +import Data.Monoid ((<>)) +import Data.Time.Clock (getCurrentTime) +import System.Exit (ExitCode (ExitFailure), + exitWith) migrationTableName :: ByteString migrationTableName = "installed_migrations" @@ -37,9 +34,18 @@ revertSql = "DROP TABLE " <> migrationTableName hasqlBackend :: Connection -> Backend hasqlBackend conn = Backend { isBootstrapped = do - exists <- run (query () (statement "SELECT migration_id FROM installed_migrations WHERE FALSE" H.Encode.unit unit True)) conn + exists <- run ( + statement + () + (Statement + "SELECT migration_id FROM installed_migrations WHERE FALSE" + H.Encode.unit + unit + True + ) + ) conn return $ case exists of - Left _ -> False + Left _ -> False Right _ -> True , getBootstrapMigration = do ts <- getCurrentTime @@ -53,12 +59,12 @@ hasqlBackend conn = , applyMigration = \m -> do reportAction <- run (sql $ mApply m) conn case reportAction of - Left e -> reportSqlError e + Left e -> reportSqlError e Right i -> return i register <- run (sql $ "INSERT INTO " <> migrationTableName <> " (migration_id) VALUES ('" <> mId m <> "')") conn case register of - Left e -> reportSqlError e + Left e -> reportSqlError e Right i -> return i return () @@ -68,27 +74,36 @@ hasqlBackend conn = Just revQ -> do action <- run (sql revQ) conn case action of - Left e -> reportSqlError e + Left e -> reportSqlError e Right i -> return i -- Remove migration from installed_migrations in either case. deleteAction <- run (sql $ "DELETE FROM " <> migrationTableName <> " WHERE migration_id = '" <> mId m <> "'") conn case deleteAction of - Left e -> reportSqlError e + Left e -> reportSqlError e Right i -> return i return () , getMigrations = do - selectNames <- run (query () (statement "SELECT migration_id FROM installed_migrations" H.Encode.unit (rowsList $ value bytea) False)) conn + selectNames <- run ( + statement + () + (Statement + "SELECT migration_id FROM installed_migrations" + H.Encode.unit + (rowList $ column bytea) + False + ) + ) conn results <- case selectNames of - Left e -> reportSqlError e + Left e -> reportSqlError e Right names -> return names return results , disconnectBackend = release conn } -reportSqlError :: Error -> IO a +reportSqlError :: QueryError -> IO a reportSqlError e = do putStrLn $ "\n" <> "A database error occurred: " <> show e exitWith (ExitFailure 1) diff --git a/stack.yaml b/stack.yaml index 8ade283..360360f 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-12.8 +resolver: lts-13.24 packages: - . @@ -6,4 +6,4 @@ packages: extra-deps: - HsSyck-0.53 - yaml-light-0.1.4 -- hasql-1.1.1 +# - hasql-1.1.1 From cea637e53f8487e0955fb7cdc736fbee5434d4e1 Mon Sep 17 00:00:00 2001 From: artik008 Date: Thu, 6 Jun 2019 15:43:04 +0300 Subject: [PATCH 2/2] Remove comments --- stack.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/stack.yaml b/stack.yaml index 360360f..8c58889 100644 --- a/stack.yaml +++ b/stack.yaml @@ -6,4 +6,3 @@ packages: extra-deps: - HsSyck-0.53 - yaml-light-0.1.4 -# - hasql-1.1.1