From 6344017db34ae6d415c3be0a039c2ecf552b507a Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 20 Mar 2019 12:15:04 +0100 Subject: [PATCH] Ensure better, that study_{degree,terms}.{shorthand,name} isn't "" --- src/Handler/Admin.hs | 4 ++-- src/Model/Migration.hs | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Handler/Admin.hs b/src/Handler/Admin.hs index bf5a29f6d..dd3252b9b 100644 --- a/src/Handler/Admin.hs +++ b/src/Handler/Admin.hs @@ -11,7 +11,7 @@ import Control.Monad.Trans.Writer (mapWriterT) import Utils.Lens -- import Data.Time --- import qualified Data.Text as T +import qualified Data.Text as Text -- import Data.Function ((&)) -- import Yesod.Form.Bootstrap3 @@ -237,7 +237,7 @@ postAdminFeaturesR = do $(widgetFile "adminFeatures") where textInputCell lensRes lensDefault = formCell id (return . view (_dbrOutput . _entityKey)) - (\row _mkUnique -> (\(res,fieldView) -> (set lensRes <$> res, fvInput fieldView)) + (\row _mkUnique -> (\(res,fieldView) -> (set lensRes . assertM (not . Text.null) <$> res, fvInput fieldView)) <$> mopt textField "" (Just $ row ^. lensDefault) ) diff --git a/src/Model/Migration.hs b/src/Model/Migration.hs index 38de10773..7b5fcc375 100644 --- a/src/Model/Migration.hs +++ b/src/Model/Migration.hs @@ -216,6 +216,13 @@ customMigrations = Map.fromListWith (>>) users <- [sqlQQ| SELECT DISTINCT ON ("user"."id") "user"."id", "study_features"."id" FROM "user", "study_features" WHERE "study_features"."user" = "user"."id" AND "study_features"."valid" AND "study_features"."type" = 'FieldPrimary' ORDER BY "user"."id", random(); |] forM_ users $ \(uid :: UserId, sfid :: StudyFeaturesId) -> [executeQQ| UPDATE "course_participant" SET "field" = #{sfid} WHERE "user" = #{uid} AND "field" IS NULL; |] ) + , ( AppliedMigrationKey [migrationVersion|9.0.0|] [version|10.0.0|] + , do + whenM (columnExists "study_degree" "shorthand") $ [executeQQ| UPDATE "study_degree" SET "shorthand" = NULL WHERE "shorthand" = '' |] + whenM (columnExists "study_degree" "name") $ [executeQQ| UPDATE "study_degree" SET "name" = NULL WHERE "shorthand" = '' |] + whenM (columnExists "study_terms" "shorthand") $ [executeQQ| UPDATE "study_terms" SET "shorthand" = NULL WHERE "shorthand" = '' |] + whenM (columnExists "study_terms" "name") $ [executeQQ| UPDATE "study_terms" SET "name" = NULL WHERE "shorthand" = '' |] + ) ]