Skip to content

Commit 96ea796

Browse files
authored
Add check if migrations dir exists before copying (#1562)
1 parent 2752f88 commit 96ea796

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

waspc/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ app todoApp {
1919

2020
### 🐞 Bug fixes / 🔧 small improvements
2121
- 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.
22+
- Fixes a bug where copying of migrations dir failed due to a missing `migrations` dir.
2223

2324

2425
## 0.11.7

waspc/src/Wasp/Generator/DbGenerator/Operations.hs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import Wasp.Generator.DbGenerator.Common
3636
webAppPrismaClientOutputDirEnv,
3737
)
3838
import qualified Wasp.Generator.DbGenerator.Jobs as DbJobs
39-
import Wasp.Generator.FileDraft.WriteableMonad (WriteableMonad (copyDirectoryRecursive))
39+
import Wasp.Generator.FileDraft.WriteableMonad (WriteableMonad (copyDirectoryRecursive, doesDirectoryExist))
4040
import qualified Wasp.Generator.Job as J
4141
import Wasp.Generator.Job.IO (printJobMsgsUntilExitReceived, readJobMessagesAndPrintThemPrefixed)
4242
import qualified Wasp.Generator.WriteFileDrafts as Generator.WriteFileDrafts
@@ -62,7 +62,7 @@ finalizeMigration :: Path' Abs (Dir ProjectRootDir) -> Path' Abs (Dir DbMigratio
6262
finalizeMigration genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs onLastDbConcurrenceChecksumFileRefreshAction = do
6363
-- NOTE: We are updating a managed CopyDirFileDraft outside the normal generation process, so we must invalidate the checksum entry for it.
6464
Generator.WriteFileDrafts.removeFromChecksumFile genProjectRootDirAbs [Right $ SP.castDir dbMigrationsDirInProjectRootDir]
65-
res <- copyMigrationsBackToSource genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs
65+
res <- copyMigrationsBackToSourceIfTheyExist genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs
6666
applyOnLastDbConcurrenceChecksumFileRefreshAction
6767
return res
6868
where
@@ -76,12 +76,20 @@ finalizeMigration genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs onLast
7676
IgnoreOnLastDbConcurrenceChecksumFile -> return ()
7777

7878
-- | Copies the DB migrations from the generated project dir back up to theh wasp project dir
79-
copyMigrationsBackToSource :: Path' Abs (Dir ProjectRootDir) -> Path' Abs (Dir DbMigrationsDir) -> IO (Either String ())
80-
copyMigrationsBackToSource genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs =
81-
copyDirectoryRecursive genProjectMigrationsDir waspMigrationsDir >> return (Right ())
82-
`catch` (\e -> return $ Left $ show (e :: P.PathException))
83-
`catch` (\e -> return $ Left $ show (e :: IOError))
79+
copyMigrationsBackToSourceIfTheyExist ::
80+
Path' Abs (Dir ProjectRootDir) ->
81+
Path' Abs (Dir DbMigrationsDir) ->
82+
IO (Either String ())
83+
copyMigrationsBackToSourceIfTheyExist genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs = do
84+
doesDirectoryExist (SP.fromAbsDir genProjectMigrationsDir) >>= \case
85+
False -> return $ Right ()
86+
True -> copyMigrationsDir
8487
where
88+
copyMigrationsDir =
89+
copyDirectoryRecursive genProjectMigrationsDir waspMigrationsDir >> return (Right ())
90+
`catch` (\e -> return $ Left $ show (e :: P.PathException))
91+
`catch` (\e -> return $ Left $ show (e :: IOError))
92+
8593
waspMigrationsDir = dbMigrationsDirInWaspProjectDirAbs
8694
genProjectMigrationsDir = genProjectRootDirAbs </> dbRootDirInProjectRootDir </> dbMigrationsDirInDbRootDir
8795

0 commit comments

Comments
 (0)