Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check if migrations dir exists before copying #1562

Merged
merged 3 commits into from
Nov 9, 2023

Conversation

infomiho
Copy link
Contributor

@infomiho infomiho commented Nov 8, 2023

Closes #1352

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice @infomiho ! I approved, but also left one/two comments that possibly improve code a bit, take a look and do as you like with them.

Comment on lines 80 to 90
copyMigrationsBackToSource genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs = do
doesMigrationsDirExist <- doesDirectoryExist $ SP.fromAbsDir genProjectMigrationsDir

if doesMigrationsDirExist
then copyMigrationsDir
else return $ Right ()
where
copyMigrationsDir =
copyDirectoryRecursive genProjectMigrationsDir waspMigrationsDir >> return (Right ())
`catch` (\e -> return $ Left $ show (e :: P.PathException))
`catch` (\e -> return $ Left $ show (e :: IOError))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
copyMigrationsBackToSource genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs = do
doesMigrationsDirExist <- doesDirectoryExist $ SP.fromAbsDir genProjectMigrationsDir
if doesMigrationsDirExist
then copyMigrationsDir
else return $ Right ()
where
copyMigrationsDir =
copyDirectoryRecursive genProjectMigrationsDir waspMigrationsDir >> return (Right ())
`catch` (\e -> return $ Left $ show (e :: P.PathException))
`catch` (\e -> return $ Left $ show (e :: IOError))
copyMigrationsBackToSource genProjectRootDirAbs dbMigrationsDirInWaspProjectDirAbs = do
doesDirectoryExist (SP.fromAbsDir genProjectMigrationsDir) >>= \case ->
False -> return $ Right ()
True -> copyDirectoryRecursive genProjectMigrationsDir waspMigrationsDir >> return (Right ())
`catch` (\e -> return $ Left $ show (e :: P.PathException))
`catch` (\e -> return $ Left $ show (e :: IOError))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also consider renaming whole functoin to copyMigrationsBackToSourceIfTheyExist, but I am not sure, we can also skip it maybe.

@infomiho infomiho merged commit 96ea796 into main Nov 9, 2023
4 checks passed
@infomiho infomiho deleted the miho-migrations-folder-migrate-error branch November 9, 2023 12:17
martinovicdev pushed a commit to martinovicdev/wasp that referenced this pull request Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Running wasp db migrate-dev without any migrations causes a weird error
2 participants