Quotes in tableExists for Migration
This commit is contained in:
parent
c27f8b390b
commit
b0cabdac15
@ -87,30 +87,19 @@ migrateAll = do
|
||||
customMigrations :: MonadIO m => Map (Key AppliedMigration) (ReaderT SqlBackend m ())
|
||||
customMigrations = Map.fromListWith (>>)
|
||||
[ ( AppliedMigrationKey [migrationVersion|initial|] [version|0.0.0|]
|
||||
, do -- New theme format
|
||||
haveUserTable <- [sqlQQ| SELECT to_regclass('user'); |]
|
||||
|
||||
case haveUserTable :: [Maybe (Single Text)] of
|
||||
[Just _] -> do
|
||||
userThemes <- [sqlQQ| SELECT 'id', 'theme' FROM 'user'; |]
|
||||
forM_ userThemes $ \(uid, Single str) -> case stripPrefix "theme--" str of
|
||||
Just v
|
||||
| Just theme <- fromPathPiece v -> update uid [UserTheme =. theme]
|
||||
other -> error $ "Could not parse theme: " <> show other
|
||||
_other -> return ()
|
||||
, whenM (tableExists "user") $ do -- New theme format
|
||||
userThemes <- [sqlQQ| SELECT 'id', 'theme' FROM 'user'; |]
|
||||
forM_ userThemes $ \(uid, Single str) -> case stripPrefix "theme--" str of
|
||||
Just v
|
||||
| Just theme <- fromPathPiece v -> update uid [UserTheme =. theme]
|
||||
other -> error $ "Could not parse theme: " <> show other
|
||||
)
|
||||
, ( AppliedMigrationKey [migrationVersion|0.0.0|] [version|1.0.0|]
|
||||
, do -- Better JSON encoding
|
||||
|
||||
haveSheetTable <- [sqlQQ| SELECT to_regclass('sheet'); |]
|
||||
|
||||
case haveSheetTable :: [Maybe (Single Text)] of
|
||||
[Just _] ->
|
||||
[executeQQ|
|
||||
ALTER TABLE 'sheet' ALTER COLUMN 'type' TYPE json USING 'type'::json;
|
||||
ALTER TABLE 'sheet' ALTER COLUMN 'grouping' TYPE json USING 'grouping'::json;
|
||||
|]
|
||||
_other -> return ()
|
||||
, whenM (tableExists "sheet") $ -- Better JSON encoding
|
||||
[executeQQ|
|
||||
ALTER TABLE 'sheet' ALTER COLUMN 'type' TYPE json USING 'type'::json;
|
||||
ALTER TABLE 'sheet' ALTER COLUMN 'grouping' TYPE json USING 'grouping'::json;
|
||||
|]
|
||||
)
|
||||
, ( AppliedMigrationKey [migrationVersion|1.0.0|] [version|2.0.0|]
|
||||
, whenM (tableExists "school") $ do -- SchoolId is the Shorthand CI Text now
|
||||
@ -168,7 +157,7 @@ customMigrations = Map.fromListWith (>>)
|
||||
|
||||
tableExists :: MonadIO m => Text -> ReaderT SqlBackend m Bool
|
||||
tableExists table = do
|
||||
haveSchoolTable <- [sqlQQ| SELECT to_regclass(#{table}); |]
|
||||
haveSchoolTable <- [sqlQQ| SELECT to_regclass('#{table}'); |]
|
||||
case haveSchoolTable :: [Maybe (Single Text)] of
|
||||
[Just _] -> return True
|
||||
_other -> return False
|
||||
|
||||
Loading…
Reference in New Issue
Block a user