[PATCH] Set up Alembic for database migrations

Frédéric Mangano-Tarumi fmang at mg0.fr
Sun Feb 23 18:33:28 UTC 2020


Frédéric Mangano-Tarumi [2020-02-22 22:31:26 +0100]
> diff --git a/aurweb/initdb.py b/aurweb/initdb.py
> index e3e96503..c02fb961 100644
> --- a/aurweb/initdb.py
> +++ b/aurweb/initdb.py
> @@ -31,10 +33,17 @@ def feed_initial_data(conn):
>  
>  
>  def run(args):
> +    # Ensure Alembic is fine before we do the real work, in order not to fail at
> +    # the last step and leave the database in an inconsistent state. The
> +    # configuration is loaded lazily, so we query it to force its loading.
> +    alembic_config = alembic.config.Config('alembic.ini')
> +    alembic_config.get_main_option('script_location')
> +
>      engine = sqlalchemy.create_engine(aurweb.db.get_sqlalchemy_url(),
>                                        echo=(args.verbose >= 1))
>      aurweb.schema.metadata.create_all(engine)
>      feed_initial_data(engine.connect())
> +    alembic.command.stamp(alembic_config, 'head')
>  
>  
>  if __name__ == '__main__':

I’ve realized this chunk breaks the test suite because it requires
initdb to be run from the top-level directory. The test suite doesn’t
need Alembic so I’ll add a flag to initdb to disable it.


More information about the aur-dev mailing list