def install(settings, cfg_file, test_data=False): """ Installs the application. Only required to be called once per installation. """ dbsession = DBSession() transaction.begin() try: install_alembic_table(cfg_file) Base.metadata.create_all(bind=dbsession.connection()) create_country_list(dbsession) if test_data: install_test_data(dbsession, settings) if not dbsession.query(Settings).all(): dbsession.add(Settings()) for dyn_mod in dynamic_challenges.registry.values(): dyn_mod.install(dbsession.connection()) except: transaction.abort() raise else: transaction.commit()
def database(request, testapp): dbsession = DBSession() Base.metadata.create_all(bind=dbsession.connection()) if not dbsession.query(Settings).all(): dbsession.add(Settings()) def _drop(): conn = dbsession.connection() Base.metadata.drop_all(bind=conn) # TODO: Why do we have to use this literally? # If fixed test against MySQL *and* Postgres! conn.execute("COMMIT") request.addfinalizer(_drop)
def uninstall(settings): """ Remove those parts created by install """ Base.metadata.drop_all(bind=DBSession.connection()) transaction.commit()