Skip to content

Commit

Permalink
Solved crash with updating on first run
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaarsen committed Nov 25, 2021
1 parent 3e953a6 commit f4a6aff
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import random
import string
import os
from typing import Any, List, Optional, Tuple
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -90,10 +91,11 @@ def __init__(self, channel: str):
self.db_name = f"MarkovChain_{channel.replace('#', '').lower()}.db"
self._execute_queue = []

# Ensure the database is updated to the newest version
self.update_v1(channel)
self.update_v2()
self.update_v3(channel)
if os.path.isfile(self.db_name):
# Ensure the database is updated to the newest version
self.update_v1(channel)
self.update_v2()
self.update_v3(channel)

# Create database tables.
for first_char in list(string.ascii_uppercase) + ["_"]:
Expand Down Expand Up @@ -122,6 +124,15 @@ def __init__(self, channel: str):
);
"""
self.add_execute_queue(sql)
# Add a version entry
sql = """
CREATE TABLE IF NOT EXISTS Version (
version INTEGER
);
"""
self.add_execute_queue(sql)
self.add_execute_queue("DELETE FROM Version;")
self.add_execute_queue("INSERT INTO Version (version) VALUES (3);")
self.execute_commit()

# Used for randomly picking a Markov Grammar if only one word is given
Expand Down

0 comments on commit f4a6aff

Please sign in to comment.