Closed jeremyjung closed 3 years ago
Thank you! Yes this is an issue and I think we can solve it by running the pending check inside of a middleware. That way it will show the regular error message screen instead of hanging forever :D
I was looking into how Rails does this and they have a file watcher so that it only runs the check when a migration file has been added. Seems like an ok way to go about it, what do y'all think?
I think the file watcher is a better long term way to do it, but I'm not sure it is worth the extra effort to implement and maintain right now. I think maybe what we can/should do is exit
instead of just raising if a pending migration is missing. That way the server never starts at all until the pending migrations are resolved. That might be the simplest way forward for now.
Ideally we'd raise only if a migration was added (like you mentioned) and also have a button on the error page to run pending migrations right away but that'd probably require a pretty large amount of work :S
I believe everything is in place now to efficiently run this check for every request in development. The solution would be to add a middleware handler in Avram and then update lucky_cli to include it for generated apps.
I was thinking that the middleware would access the database info https://github.com/luckyframework/avram/blob/bd5b7eef9368f72f2f109338dfa4380b16561f3c/src/avram/database.cr#L44-L46 but that is memoized and if the migrations are run without restarting the app, we'll never know.
Since we only need to check that migration table against the migrations in the folder, we shouldn't need the database info. One thing I noticed is that we issue a SQL query for each and every migration. Maybe we could refactor to select them all?
(Not a bug, just a comment on error experience)
After running lucky dev with a pending migration, there is a warning that there is a pending migration. This is great! However the text below it suggests that the app is still running. If you attempt to go to the webpage (localhost:3001) the web browser hangs.
Some potential ideas: