Update database.py
Browse files- database.py +10 -8
database.py
CHANGED
|
@@ -4,10 +4,10 @@ from flask import g
|
|
| 4 |
|
| 5 |
def get_db_path():
|
| 6 |
if os.path.exists('/data'):
|
| 7 |
-
return '/data/
|
| 8 |
elif os.path.exists('/home/user_data'):
|
| 9 |
-
return '/home/user_data/
|
| 10 |
-
return '
|
| 11 |
|
| 12 |
def get_db():
|
| 13 |
if 'db' not in g:
|
|
@@ -28,15 +28,17 @@ def init_db(app):
|
|
| 28 |
cursor = db.cursor()
|
| 29 |
|
| 30 |
cursor.execute('''
|
| 31 |
-
CREATE TABLE IF NOT EXISTS
|
| 32 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 33 |
-
udid TEXT NOT NULL UNIQUE
|
|
|
|
|
|
|
| 34 |
)
|
| 35 |
''')
|
| 36 |
|
| 37 |
-
|
| 38 |
-
cursor.execute('SELECT COUNT(*) FROM udids')
|
| 39 |
if cursor.fetchone()[0] == 0:
|
| 40 |
-
cursor.
|
|
|
|
| 41 |
|
| 42 |
db.commit()
|
|
|
|
| 4 |
|
| 5 |
def get_db_path():
|
| 6 |
if os.path.exists('/data'):
|
| 7 |
+
return '/data/users.db'
|
| 8 |
elif os.path.exists('/home/user_data'):
|
| 9 |
+
return '/home/user_data/users.db'
|
| 10 |
+
return 'users.db'
|
| 11 |
|
| 12 |
def get_db():
|
| 13 |
if 'db' not in g:
|
|
|
|
| 28 |
cursor = db.cursor()
|
| 29 |
|
| 30 |
cursor.execute('''
|
| 31 |
+
CREATE TABLE IF NOT EXISTS users (
|
| 32 |
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 33 |
+
udid TEXT NOT NULL UNIQUE,
|
| 34 |
+
paid BOOLEAN DEFAULT FALSE,
|
| 35 |
+
limit INTEGER DEFAULT 4
|
| 36 |
)
|
| 37 |
''')
|
| 38 |
|
| 39 |
+
cursor.execute('SELECT COUNT(*) FROM users')
|
|
|
|
| 40 |
if cursor.fetchone()[0] == 0:
|
| 41 |
+
cursor.executemany('INSERT INTO users (udid, paid, limit) VALUES (?, ?, ?)',
|
| 42 |
+
[('test_udid_1', True, 4), ('test_udid_2', False, 4)])
|
| 43 |
|
| 44 |
db.commit()
|