Skip to content

Commit

Permalink
feat: better creation of Users table
Browse files Browse the repository at this point in the history
  • Loading branch information
haasal committed Aug 22, 2022
1 parent a846de8 commit 0235596
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions tardis/rest/app/crud.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
CREATE_USERS = """CREATE TABLE Users (
CREATE_USERS = """CREATE TABLE IF NOT EXISTS Users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_name TEXT NOT NULL UNIQUE,
hashed_password TEXT NOT NULL,
scopes TEXT NOT NULL
)"""

ADD_USER = "INSERT INTO Users (user_name, hashed_password, scopes) VALUES (?, ?, ?)"

GET_USER = "SELECT user_name, hashed_password, scopes FROM Users WHERE user_name = ?"

DELETE_USER = "DELETE FROM Users WHERE user_name = ?"

DUMP_USERS = "SELECT user_name, hashed_password, scopes FROM Users"


Expand Down
6 changes: 1 addition & 5 deletions tardis/rest/app/userdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ def __init__(self, path: str):
self.path = path

def try_create_users(self):
try:
self.execute(CREATE_USERS)
except sqlite3.OperationalError as e:
if str(e) != "table Users already exists":
raise e
self.execute(CREATE_USERS)

def drop_users(self):
self.execute("DROP TABLE Users")
Expand Down

0 comments on commit 0235596

Please sign in to comment.