-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
43 lines (31 loc) · 1.13 KB
/
database.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
import sqlite3
import argparse
schema = open("schema.sql", "r").read()
def create():
connection = sqlite3.connect("db.sqlite3")
cursor = connection.cursor()
cursor.execute(schema)
connection.commit()
cursor.close()
connection.close()
def migrate():
connection = sqlite3.connect("db.sqlite3")
cursor = connection.cursor()
cursor.execute(schema)
cursor.execute("INSERT INTO user (id, discord_id, last_fm_username) SELECT * FROM discordLastFMUser")
cursor.execute("DROP TABLE discordLastFMUser")
connection.commit()
cursor.close()
connection.close()
parser = argparse.ArgumentParser(description="Run database actions for the wurlitzer instance.")
parser.add_argument('-create', help="Create a new wurlitzer database", action='store_true')
parser.add_argument('-migrate', help="Migrate an old wurlitzer database", action='store_true')
args = parser.parse_args()
if args.create and args.migrate:
print("You cannot create as well as migrate at the same time!")
elif args.create:
create()
elif args.migrate:
migrate()
else:
print("-create or -migrate must be specified!")