-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_db.py
64 lines (56 loc) · 2.04 KB
/
setup_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import mysql.connector
from player import Player
from character import Character, CharacterClass, Race, race_enum_mapping, class_enum_mapping
def create_tables(cursor, mydb):
# Create the players table
cursor.execute("""
CREATE TABLE IF NOT EXISTS players (
player_id INT AUTO_INCREMENT PRIMARY KEY,
player_name VARCHAR(255) NOT NULL,
discord_username VARCHAR(255) NOT NULL
)
""")
# Create the characters table
cursor.execute("""
CREATE TABLE IF NOT EXISTS characters (
character_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
race ENUM('Human', 'Elf', 'Dragonborn', 'Aasimar') NOT NULL,
class ENUM('Rogue', 'Wizard', 'Barbarian', 'Paladin') NOT NULL,
player_id INT,
FOREIGN KEY (player_id) REFERENCES players(player_id)
)
""")
# Create the "bag_of_holding" table if it doesn't exist
cursor.execute("""
CREATE TABLE IF NOT EXISTS bag_of_holding (
id INT AUTO_INCREMENT PRIMARY KEY,
item VARCHAR(255) NOT NULL,
quantity INT NOT NULL DEFAULT 1,
description VARCHAR(255)
)
""")
mydb.commit()
print("All tables were created successfully")
# def setup_characters(character, cursor, mydb):
# mysql_race = race_enum_mapping[character.race]
# mysql_char_class = class_enum_mapping[character.char_class]
#
# cursor.execute("""
# INSERT INTO characters (name, race, class, player_id)
# VALUES (%s, %s, %s, %s)
# """, (character.name, mysql_race, mysql_char_class, character.player_id))
#
# mydb.commit()
#
# print('Inserted Character')
#
# def setup_player(player, cursor, mydb):
# cursor.execute("""
# INSERT INTO players (player_name, discord_username)
# VALUES (%s, %s)
# """, (player.player_name, player.discord_username))
#
# mydb.commit()
#
# print('Inserted Player')