1

Scenario

  • I have a Python Flask app with a Postgres DB which I would like to deploy to multiple apps on Heroku.
  • My Procfile assures that my database migrations are done after every build with release: flask db upgrade.
  • I would like to automate the setup of a new app with a bunch of Heroku commands, i.e. create the app, do all the config and add the newly created app to my Heroku pipeline.

Problem

When the new app is being built the first time, it tries to do flask db upgrade but the database is not yet created - so it fails. However, I usually create the database with the following Flask command from my run.py which is not available if the app is not build.

@app.cli.command()
def create_db():
    """
    Initializes the database.
    Creates all tables and indexes.
    """
    db.drop_all()
    db.create_all()
    db.session.commit()
    print("Successfully created fresh database.")

I guess, there is a simple solution to this "deadlock". Any suggestions are welcome.

Thomas
  • 11
  • 2

0 Answers0