Add check if migrations dir exists before copying (#1562)

This commit is contained in:
Mihovil Ilakovac 2023-11-09 13:17:45 +01:00 committed by GitHub
parent 2752f889c8
commit 96ea796067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -19,6 +19,7 @@ app todoApp {
### 🐞 Bug fixes / 🔧 small improvements
- Changed the minimum number of machines that a server app is using when deployed to Fly.io from 0 to 1. This prevents the server app from shutting down when there are no requests to it. There might be some other work that the server is doing e.g. running periodic Jobs or sending e-mails, so we want to make sure that the server is always running.
- Fixes a bug where copying of migrations dir failed due to a missing `migrations` dir.
## 0.11.7

View File

@ -36,7 +36,7 @@ import Wasp.Generator.DbGenerator.Common
webAppPrismaClientOutputDirEnv,
)
import qualified Wasp.Generator.DbGenerator.Jobs as DbJobs
import Wasp.Generator.FileDraft.WriteableMonad (WriteableMonad (copyDirectoryRecursive))
import Wasp.Generator.FileDraft.WriteableMonad (WriteableMonad (copyDirectoryRecursive, doesDirectoryExist))
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.IO (printJobMsgsUntilExitReceived, readJobMessagesAndPrintThemPrefixed)
import qualified Wasp.Generator.WriteFileDrafts as Generator.WriteFileDrafts
@ -62,7 +62,7 @@ finalizeMigration :: Path' Abs (Dir ProjectRootDir) -> Path' Abs (Dir DbMigratio
finalizeMigration genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs onLastDbConcurrenceChecksumFileRefreshAction = do
-- NOTE: We are updating a managed CopyDirFileDraft outside the normal generation process, so we must invalidate the checksum entry for it.
Generator.WriteFileDrafts.removeFromChecksumFile genProjectRootDirAbs [Right $ SP.castDir dbMigrationsDirInProjectRootDir]
res <- copyMigrationsBackToSource genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs
res <- copyMigrationsBackToSourceIfTheyExist genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs
applyOnLastDbConcurrenceChecksumFileRefreshAction
return res
where
@ -76,12 +76,20 @@ finalizeMigration genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs onLast
IgnoreOnLastDbConcurrenceChecksumFile -> return ()
-- | Copies the DB migrations from the generated project dir back up to theh wasp project dir
copyMigrationsBackToSource :: Path' Abs (Dir ProjectRootDir) -> Path' Abs (Dir DbMigrationsDir) -> IO (Either String ())
copyMigrationsBackToSource genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs =
copyDirectoryRecursive genProjectMigrationsDir waspMigrationsDir >> return (Right ())
`catch` (\e -> return $ Left $ show (e :: P.PathException))
`catch` (\e -> return $ Left $ show (e :: IOError))
copyMigrationsBackToSourceIfTheyExist ::
Path' Abs (Dir ProjectRootDir) ->
Path' Abs (Dir DbMigrationsDir) ->
IO (Either String ())
copyMigrationsBackToSourceIfTheyExist genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs = do
doesDirectoryExist (SP.fromAbsDir genProjectMigrationsDir) >>= \case
False -> return $ Right ()
True -> copyMigrationsDir
where
copyMigrationsDir =
copyDirectoryRecursive genProjectMigrationsDir waspMigrationsDir >> return (Right ())
`catch` (\e -> return $ Left $ show (e :: P.PathException))
`catch` (\e -> return $ Left $ show (e :: IOError))
waspMigrationsDir = dbMigrationsDirInWaspProjectDirAbs
genProjectMigrationsDir = genProjectRootDirAbs </> dbRootDirInProjectRootDir </> dbMigrationsDirInDbRootDir