def init_db(skip_create_db=False): """Initialize the database. * Creates the database. * Creates all tables. * Adds fixtures required to run the app. """ click.echo("Initializing the database...") db_uri = frontend.create_app().config['SQLALCHEMY_DATABASE_URI'] if not skip_create_db: init_postgres(db_uri) create_extension(db_uri) click.echo("Creating tables... ", nl=False) data_utils.create_tables(frontend.create_app()) click.echo("Done!") click.echo("Adding fixtures... ") app = frontend.create_app() with app.app_context(): _fixtures.install(app, *_fixtures.all_data) click.echo("Done!") click.echo("Initialization has been completed!")
def install(app, *args): db.init_app(app) create_tables(app) for arg in args: for key, entity in arg.__dict__.iteritems(): if not key.startswith("__"): try: db.session.add(entity) db.session.flush() except: print('Failed to add %s!' % key) db.session.rollback() else: print('Added %s.' % key) db.session.commit()
def init_db(): """Initialize the database. * Creates the database. * Creates all tables. * Adds fixtures required to run the app. """ click.echo("Initializing the database...") init_postgres(frontend.create_app().config["SQLALCHEMY_DATABASE_URI"]) click.echo("Creating tables... ", nl=False) data_utils.create_tables(frontend.create_app()) click.echo("Done!") click.echo("Adding fixtures... ") app = frontend.create_app() with app.app_context(): _fixtures.install(app, *_fixtures.all_data) click.echo("Done!") click.echo("Initialization has been completed!")
def tables(): create_tables(current_app)