def initialize(cls): """Perform startup database checks. 1) Load schema if needed 2) Run migrations if needed 3) Check if initial sync has completed """ log.info("[INIT] Welcome to hive!") # create db schema if needed if not cls._is_schema_loaded(): log.info("[INIT] Create db schema...") setup(cls.db()) cls._before_initial_sync() # perform db migrations cls._check_migrations() # check if initial sync complete cls._is_initial_sync = cls._is_feed_cache_empty() if cls._is_initial_sync: log.info("[INIT] Continue with initial sync...") else: log.info("[INIT] Hive initialized.")
def run(): # if tables not created, do so now if not query_row('SHOW TABLES'): print("[INIT] No tables found. Initializing db...") setup() #TODO: if initial sync is interrupted, cache never rebuilt #TODO: do not build partial feed_cache during init_sync # if this is the initial sync, batch updates until very end is_initial_sync = not query_one("SELECT 1 FROM hive_posts_cache LIMIT 1") if is_initial_sync: print("[INIT] *** Initial sync ***") else: # perform cleanup in case process did not exit cleanly cache_missing_posts() # fast block sync strategies sync_from_checkpoints(is_initial_sync) sync_from_steemd(is_initial_sync) if is_initial_sync: print("[INIT] *** Initial sync complete. Rebuilding cache. ***") cache_missing_posts() rebuild_feed_cache() # initialization complete. follow head blocks listen_steemd()
def run(): if db_needs_setup(): print("[INIT] Initializing db...") setup() #TODO: if initial sync is interrupted, cache never rebuilt #TODO: do not build partial feed_cache during init_sync # if this is the initial sync, batch updates until very end is_initial_sync = not query_one("SELECT 1 FROM hive_posts_cache LIMIT 1") if is_initial_sync: print("[INIT] *** Initial sync. db_last_block: %d ***" % db_last_block()) else: # perform cleanup in case process did not exit cleanly cache_missing_posts() # prefetch id->name memory map Accounts.load_ids() # fast block sync strategies sync_from_checkpoints(is_initial_sync) sync_from_steemd(is_initial_sync) Accounts.cache_old() Accounts.update_ranks() if is_initial_sync: print("[INIT] *** Initial sync complete. Rebuilding cache. ***") cache_missing_posts() rebuild_feed_cache() # initialization complete. follow head blocks listen_steemd()
def initialize(cls): # create db schema if needed if not cls._is_schema_loaded(): print("[INIT] Initializing db...") setup() # perform db migrations cls._check_migrations() # check if initial sync complete cls._is_initial_sync = cls._is_feed_cache_empty() if cls._is_initial_sync: print("[INIT] Continue with initial sync...")
def initialize(cls): """Perform startup database checks. 1) Load schema if needed 2) Run migrations if needed 3) Check if initial sync has completed """ log.info("[INIT] Welcome to hive!") # create db schema if needed if not cls._is_schema_loaded(): log.info("[INIT] Create db schema...") setup(cls.db()) # check if initial sync complete cls._is_initial_sync = True log.info("[INIT] Continue with initial sync...")
def ensure_schema(database_url): """re-create db schema (WARN: will wipe data)""" teardown(database_url) setup(database_url)