1

I have setup a build pipeline on Azure to execute pytests and such. In addition, I'd also like to check if no migrations have been missed.

Running the alembic command with --autogenerate will generate a new migration file in case it isn't there yet.

When executing the revision command just by itself

 alembic revision --autogenerate

the output looks something like this (1)

INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.ddl.postgresql] Detected sequence ...
INFO  [alembic.ddl.postgresql] Detected sequence ...
INFO  [alembic.ddl.postgresql] Detected sequence ...
INFO  [alembic.autogenerate.compare] Detected added column ...
  Generating /.../alembic/versions/dc3dae7487df_.py ... done

I've tried it with the following check

 [[ $(alembic revision --autogenerate | grep "^Generating.*done$") ]] && echo "test"

However, the grep doesn't seem to work on the alembic output since I never receive the echo test even if a new migration file is generated.

Running the command

alembic revision --autogenerate | grep 'Generating.*done' | cat -v

produces the output as in (1).

Changing the regex also doesn't give the expected result

[[ $(alembic revision --autogenerate | grep "^[[:blank:]]*Generating.*done\r$") ]] && echo "test"
wasp256
  • 5,943
  • 12
  • 72
  • 119

1 Answers1

1

Given our discussion where we discovered that the alembic output was going to stderr instead of stdout, this will do what I think you want:

[[ $(alembic revision --autogenerate 2>&1 | grep '^[[:blank:]]*Generating.*done[[:blank:]]*$') ]] && echo "test"

If that's still not what you want then edit your question again to clarify further.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185