From aa54574e465b2ea2528734ff6a59fce78ba9076d Mon Sep 17 00:00:00 2001 From: Vitalii Guzeev Date: Mon, 24 Sep 2018 20:43:00 +0300 Subject: [PATCH] Update correspondingly to new version of dbmigrations --- dbmigrations-mysql.cabal | 5 ++- .../Schema/Migrations/Backend/MySQL.hs | 41 ++++++++++--------- test/{TestDriver.hs => Main.hs} | 0 3 files changed, 25 insertions(+), 21 deletions(-) rename test/{TestDriver.hs => Main.hs} (100%) diff --git a/dbmigrations-mysql.cabal b/dbmigrations-mysql.cabal index 93b81a5..01499af 100644 --- a/dbmigrations-mysql.cabal +++ b/dbmigrations-mysql.cabal @@ -37,6 +37,8 @@ Library base >= 4 && < 5, dbmigrations >= 2, time >= 1.4, + text >= 1.2.3.0, + string-conversions >= 0.4, mysql >= 0.1.2, mysql-simple >= 0.2.2.5, split >= 0.2.2 @@ -75,7 +77,6 @@ test-suite dbmigrations-mysql-tests other-modules: BackendTest - TestDriver if impl(ghc >= 6.12.0) ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields @@ -84,4 +85,4 @@ test-suite dbmigrations-mysql-tests ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields Hs-Source-Dirs: test - Main-is: TestDriver.hs + Main-is: Main.hs diff --git a/src/Database/Schema/Migrations/Backend/MySQL.hs b/src/Database/Schema/Migrations/Backend/MySQL.hs index 1ad5758..6917663 100644 --- a/src/Database/Schema/Migrations/Backend/MySQL.hs +++ b/src/Database/Schema/Migrations/Backend/MySQL.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE OverloadedStrings #-} module Database.Schema.Migrations.Backend.MySQL ( connectMySQL , mysqlBackend) where @@ -11,6 +12,8 @@ import Database.Schema.Migrations.Migration import Data.List.Split (wordsBy) import Data.Char (isSpace, toLower) import Data.Time.Clock (getCurrentTime) +import Data.Text (Text) +import Data.String.Conversions (cs, (<>)) import Data.String (fromString) import Data.Maybe (fromMaybe, listToMaybe) import qualified Database.MySQL.Base as Base @@ -46,8 +49,8 @@ mysqlBackend conn = Backend {isBootstrapped = fmap ((Just migrationTableName ==) . listToMaybe . fmap fromOnly) (query conn - (fromString "SELECT table_name FROM information_schema.tables WHERE table_name = ? AND table_schema = database()") - (Only migrationTableName) :: IO [Only String]) + ("SELECT table_name FROM information_schema.tables WHERE table_name = ? AND table_schema = database()") + (Only migrationTableName) :: IO [Only Text]) ,getBootstrapMigration = do ts <- getCurrentTime return ((newMigration rootMigrationName) {mApply = createSql @@ -58,12 +61,12 @@ mysqlBackend conn = ,mTimestamp = Just ts}) ,applyMigration = \m -> - do execute_ conn (fromString (mApply m)) + do _ <- execute_ conn (fromString . cs $ mApply m) discardResults conn - execute conn - (fromString - ("INSERT INTO " ++ - migrationTableName ++ + _ <- execute conn + (fromString . cs $ + ("INSERT INTO " <> + migrationTableName <> " (migration_id) VALUES (?)")) (Only (mId m)) return () @@ -72,22 +75,22 @@ mysqlBackend conn = do case mRevert m of Nothing -> return () Just sql -> - do execute_ conn (fromString sql) + do _ <- execute_ conn (fromString . cs $ sql) return () discardResults conn -- Remove migration from installed_migrations in either case. - execute + _ <- execute conn - (fromString - ("DELETE FROM " ++ - migrationTableName ++ " WHERE migration_id = ?")) + (fromString . cs $ + ("DELETE FROM " <> + migrationTableName <> " WHERE migration_id = ?")) (Only (mId m)) return () ,getMigrations = do results <- query_ conn - (fromString - ("SELECT migration_id FROM " ++ migrationTableName)) + (fromString . cs $ + ("SELECT migration_id FROM " <> migrationTableName)) return (map fromOnly results) ,commitBackend = commit conn ,rollbackBackend = rollback conn @@ -98,11 +101,11 @@ discardResults conn = do more <- Base.nextResult conn when more (discardResults conn) -migrationTableName :: String +migrationTableName :: Text migrationTableName = "installed_migrations" -createSql :: String -createSql = "CREATE TABLE " ++ migrationTableName ++ " (migration_id TEXT)" +createSql :: Text +createSql = "CREATE TABLE " <> migrationTableName <> " (migration_id TEXT)" -revertSql :: String -revertSql = "DROP TABLE " ++ migrationTableName +revertSql :: Text +revertSql = "DROP TABLE " <> migrationTableName diff --git a/test/TestDriver.hs b/test/Main.hs similarity index 100% rename from test/TestDriver.hs rename to test/Main.hs