mirror of
				https://gitlab.com/questable/questable_bot
				synced 2025-10-31 20:30:05 +01:00 
			
		
		
		
	Move schema to schema.sql
This commit is contained in:
		
							
								
								
									
										28
									
								
								bot.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										28
									
								
								bot.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -604,31 +604,13 @@ def sigterm_handler(signal, frame, db): | |||||||
|     sys.exit(0) |     sys.exit(0) | ||||||
|  |  | ||||||
|  |  | ||||||
| db = sqlite3.connect("questable.db", check_same_thread=False) |  | ||||||
| cursor = db.cursor() |  | ||||||
| signal.signal(signal.SIGTERM, lambda x, y: sigterm_handler(x, y, db)) | signal.signal(signal.SIGTERM, lambda x, y: sigterm_handler(x, y, db)) | ||||||
|  |  | ||||||
| # Set up tables | # Set up database and tables | ||||||
| queries = [ | db = sqlite3.connect("questable.db", check_same_thread=False) | ||||||
|        ("CREATE TABLE IF NOT EXISTS quests(chat_id int NOT NULL, qid int NOT" | cursor = db.cursor() | ||||||
|            " NULL, name varchar(255), difficulty int, importance int, " | with open('schema.sql') as f: | ||||||
|            "state int DEFAULT 0, UNIQUE(chat_id, qid));"), |     cursor.executescript(f.read()) | ||||||
|  |  | ||||||
|        ("CREATE TABLE IF NOT EXISTS side_quests(chat_id int NOT NULL, qid int " |  | ||||||
|            "NOT NULL, name varchar(255), difficulty int, importance int, " |  | ||||||
|            "state int DEFAULT 0, UNIQUE(chat_id, qid));"), |  | ||||||
|  |  | ||||||
|        ("CREATE TABLE IF NOT EXISTS points(chat_id int PRIMARY KEY, points " |  | ||||||
|            "int);"), |  | ||||||
|  |  | ||||||
|        ("CREATE TABLE IF NOT EXISTS state(chat_id int PRIMARY KEY, state " |  | ||||||
|            "varchar(10), extra varchar(10));"), |  | ||||||
|  |  | ||||||
|        ("CREATE TABLE IF NOT EXISTS tokens(chat_id int, token varchar(36)," |  | ||||||
|            "UNIQUE(chat_id, token));"), |  | ||||||
|         ] |  | ||||||
| for query in queries: |  | ||||||
|     cursor.execute(query) |  | ||||||
| db.commit() | db.commit() | ||||||
|  |  | ||||||
| updater = Updater(token=config.api_key) | updater = Updater(token=config.api_key) | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								schema.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								schema.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  | CREATE TABLE IF NOT EXISTS quests(chat_id int NOT NULL, qid int NOT NULL, name varchar(255), difficulty int, importance int, state int DEFAULT 0, UNIQUE(chat_id, qid)); | ||||||
|  | CREATE TABLE IF NOT EXISTS side_quests(chat_id int NOT NULL, qid int NOT NULL, name varchar(255), difficulty int, importance int, state int DEFAULT 0, UNIQUE(chat_id, qid)); | ||||||
|  | CREATE TABLE IF NOT EXISTS points(chat_id int PRIMARY KEY, points int); | ||||||
|  | CREATE TABLE IF NOT EXISTS state(chat_id int PRIMARY KEY, state varchar(10), extra varchar(10)); | ||||||
|  | CREATE TABLE IF NOT EXISTS tokens(chat_id int, token varchar(36) PRIMARY KEY); | ||||||
		Reference in New Issue
	
	Block a user