35 lines
905 B
Python
35 lines
905 B
Python
import sqlite3
|
|
import os
|
|
from flask import current_app
|
|
|
|
def init_db():
|
|
db_path = os.path.join(current_app.instance_path, 'games.db')
|
|
conn = sqlite3.connect(db_path)
|
|
cursor = conn.cursor()
|
|
|
|
# Tabelle für Spiele erstellen
|
|
cursor.execute('''
|
|
CREATE TABLE IF NOT EXISTS games (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
image TEXT,
|
|
title TEXT NOT NULL,
|
|
date TEXT,
|
|
buyer TEXT,
|
|
owned BOOLEAN NOT NULL
|
|
)
|
|
''')
|
|
|
|
# Tabelle für Benutzer erstellen
|
|
cursor.execute('''
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
username TEXT NOT NULL UNIQUE,
|
|
password TEXT NOT NULL,
|
|
role TEXT NOT NULL CHECK(role IN ('user', 'admin')),
|
|
last_login TEXT
|
|
)
|
|
''')
|
|
|
|
conn.commit()
|
|
conn.close()
|