def __init__(self, testing): self.testing = testing data_dir = get_data_dir("aw-server") ds_name = self.sid + ('-testing' if testing else '') filename = ds_name + ".v{}".format(LATEST_VERSION) + '.db' filepath = os.path.join(data_dir, filename) new_db_file = not os.path.exists(filepath) self.conn = sqlite3.connect(filepath) logger.info("Using database file: {}".format(filepath)) # Create tables self.conn.execute(CREATE_BUCKETS_TABLE) self.conn.execute(CREATE_EVENTS_TABLE) self.conn.execute(INDEX_BUCKETS_TABLE_ID) self.conn.execute(INDEX_EVENTS_TABLE_STARTTIME) self.conn.execute(INDEX_EVENTS_TABLE_ENDTIME) self.conn.execute("PRAGMA journal_mode=WAL;") self.commit() if new_db_file: logger.info("Created new SQlite db file") from aw_datastore import check_for_migration check_for_migration(self, ds_name, LATEST_VERSION) self.last_commit = datetime.now() self.num_uncommited_statements = 0
def __init__(self, testing, filepath: str = None, enable_lazy_commit=True) -> None: self.testing = testing self.enable_lazy_commit = enable_lazy_commit # Ignore the migration check if custom filepath is set ignore_migration_check = filepath is not None ds_name = self.sid + ("-testing" if testing else "") if not filepath: data_dir = get_data_dir("aw-server") filename = ds_name + ".v{}".format(LATEST_VERSION) + ".db" filepath = os.path.join(data_dir, filename) new_db_file = not os.path.exists(filepath) self.conn = sqlite3.connect(filepath) logger.info("Using database file: {}".format(filepath)) # Create tables self.conn.execute(CREATE_BUCKETS_TABLE) self.conn.execute(CREATE_EVENTS_TABLE) self.conn.execute(INDEX_BUCKETS_TABLE_ID) self.conn.execute(INDEX_EVENTS_TABLE_STARTTIME) self.conn.execute(INDEX_EVENTS_TABLE_ENDTIME) self.conn.execute("PRAGMA journal_mode=WAL;") self.commit() if new_db_file and not ignore_migration_check: logger.info("Created new SQlite db file") from aw_datastore import check_for_migration check_for_migration(self) self.last_commit = datetime.now() self.num_uncommited_statements = 0