diff --git a/waspc/ChangeLog.md b/waspc/ChangeLog.md index 058a4165bc..c3619df9fc 100644 --- a/waspc/ChangeLog.md +++ b/waspc/ChangeLog.md @@ -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 diff --git a/waspc/src/Wasp/Generator/DbGenerator/Operations.hs b/waspc/src/Wasp/Generator/DbGenerator/Operations.hs index 20696af041..c614dfb9d5 100644 --- a/waspc/src/Wasp/Generator/DbGenerator/Operations.hs +++ b/waspc/src/Wasp/Generator/DbGenerator/Operations.hs @@ -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