AngelMunoz/Migrondi

Failing to apply migrations doesn't fail a build

Closed this issue ยท 5 comments

Hello! ๐Ÿ‘‹๐Ÿป

First, I'd like to thank you for this amazing project! We're a small team writing fsharp apps and we're using migrondi to manage db migrations with postgres and it's been extremely helpful!

We just found something and I thought I'd share it with you. Here's what's happening:

We have migrondi run as part of our release pipeline. So every time we release, new migrations are applied automatically. This makes life a breeze.
But I had a typo on my latest migration script and, even though I could see the error in the logs, my release didn't fail. We build on azure devops.

What I'm thinking is that migrondi is probably not returning an exit code other than 0 when failing to apply migrations.
Ideally, it'd be best if a failure to apply migrations failed my release pipeline so we could fail fast.

Does this make sense to you? I'd be happy to send a PR with an attempt at implementing this.

Let me know if you need any more information on this.

Thank you!

Hello Vitor, first of all, I'm really happy that what I did works for your needs, one writes software and only a few times thinks where that software might be used, I'm glad it works for you. ๐Ÿคฉ

Does this make sense to you? I'd be happy to send a PR with an attempt at implementing this.

Yes it makes complete sense

as you can see here
https://github.com/AngelMunoz/Migrondi/blob/master/src/Migrondi/Program.fs#L97

I return 0 almost always
there are a few occasions I exit with 1 like here

https://github.com/AngelMunoz/Migrondi/blob/master/src/Migrondi/Program.fs#L47

so you should be able to use the same approach within these lines
https://github.com/AngelMunoz/Migrondi/blob/master/src/Migrondi/Program.fs#L69-L73
and if you care for failures in down as well
https://github.com/AngelMunoz/Migrondi/blob/master/src/Migrondi/Program.fs#L80-L82

I'll be happy to accept a PR if you need it quick, or if you can wait for me about a week I can do it myself

Thank you for your quick feedback and for the direction on how to do this!

I should be able to put together a PR for this fairly quickly ๐Ÿ˜

Before I do the release for this, are you using net5.0? just to be sure what kind of release I'll be doing

if you're still on 3.1 I'll release a 0.4.1 without net5.0 but I'm likely going 5.0 from 5 and up

I decided to keep it netcoreapp3.1 and I'll release 5.0 later in the future along with some other improvements to the code for the moment

if you're using this as a dotnet tool you should be able to install it via
dotnet tool install --global Migrondi --version 0.4.2. I'll make a GitHub release soon

Thank you so much @VitorRigoni

Oh man I'm so sorry I missed these updates! I do have dotnet 5 but I also have 3.1 and I didn't change any project settings when testing.
I can play with this on dotnet 5 and see how it behaves ๐Ÿ˜