def init_data_db(): fp = '' with profile_session_scope() as session: profile_obj = Profile.get_active(session) if profile_obj is None: raise RuntimeError('cannot init data db without active profile') fp = profile_obj.data_db_filepath log.debug('init data db at: {}'.format(fp)) engine = sqlalchemy.create_engine('sqlite:///{}'.format(fp)) data_db.configure(bind=engine) engine.execute("PRAGMA journal_mode=WAL") log.debug("check data-db schema") reset_blocks = False for table_name, table in data_base.metadata.tables.items(): log.debug("check {}-db schema".format(table.name)) if not check_table_ddl_against_model(data_db, table): log.debug("{}-db schema outdated, resetting".format(table.name)) reset_blocks = True if engine.dialect.has_table(engine, table_name): table.drop(engine) else: log.debug("{}-db schema up to date".format(table.name)) data_base.metadata.create_all(engine) if reset_blocks: data_db().query(Block).delete() return data_db
def is_first_start(profile_db): from app.models.profile import Profile """Check if the applications needs to be configured""" if not Profile.get_active(profile_db): return True else: return False