title: How to squash migrations in Alembic?
body: <p>Anyone who has worked on an old code-base is familiar with this problem: the number of migrations in your versions folder gets out of hand.  The database your application uses today looks nothing like the database it started with.  Or, perhaps more commonly, migrations get introduced that may work for the immediate update, but somehow they break the ability to revert/replay the migrations from start to finish.  In both cases, it can be nice to squash the migrations to mimic getting a fresh start.</p>
  
  <p>I've been trying to find a complete example of how to squash migrations for a Flask application using SQLalchemy and Alembic.  The closest thing I've found is <a href="https://alembic.sqlalchemy.org/en/latest/cookbook.html" rel="nofollow noreferrer">https://alembic.sqlalchemy.org/en/latest/cookbook.html</a>:</p>
  
  <pre><code># inside of a "create the database" script, first create
  # tables:
  my_metadata.create_all(engine)
  
  # then, load the Alembic configuration and generate the
  # version table, "stamping" it with the most recent rev:
  from alembic.config import Config
  from alembic import command
  alembic_cfg = Config("/path/to/yourapp/alembic.ini")
  command.stamp(alembic_cfg, "head")
  </code></pre>
  
  <p>However, this terse explanation does not explain the source of the <code>my_metadata</code>, and I'm unclear what the <code>alembic.ini</code> should contain in order to complete this task.  Does anyone know of a complete example of this task?</p>