-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit_db.py
28 lines (20 loc) · 947 Bytes
/
init_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
import sqlite3
from werkzeug.security import generate_password_hash
def init_db():
with open('schema.sql') as f:
schema = f.read()
connection = sqlite3.connect('database.db')
cursor = connection.cursor()
cursor.executescript(schema)
# Admin user creation
hashed_password = generate_password_hash('123456', method='pbkdf2:sha256')
cursor.execute("INSERT INTO users (username, email, password, is_admin) VALUES (?, ?, ?, ?)",
('admin', '[email protected]', hashed_password, 1))
cursor.execute("INSERT INTO users (username, email, password, is_admin) VALUES (?, ?, ?, ?)",
('kagan', '[email protected]', hashed_password, 0))
cursor.execute("INSERT INTO users (username, email, password, is_admin) VALUES (?, ?, ?, ?)",
('ali', '[email protected]', hashed_password, 0))
connection.commit()
connection.close()
if __name__ == '__main__':
init_db()