-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_db.py
32 lines (30 loc) · 1.52 KB
/
setup_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
29
30
31
32
from main import app
from application.sec import datastore
from application.models import db, Role, Section
from flask_security import hash_password
from werkzeug.security import generate_password_hash
with app.app_context():
db.drop_all()
db.create_all()
section = Section(section_name="Section 1", section_description="Section 1")
db.session.add(section)
# datastore.find_or_create_role(name="admin", description="User is an admin")
datastore.find_or_create_role(name="member", description="User is a Member")
datastore.find_or_create_role(name="libr", description="User is a Librarian")
db.session.commit()
# if not datastore.find_user(email="[email protected]"):
# datastore.create_user(
# email="[email protected]", password=generate_password_hash("pass123"), roles=["admin"])
if not datastore.find_user(email="[email protected]"):
datastore.create_user(name="Librarian",
email="[email protected]", password=generate_password_hash("pass123"), roles=["libr"],
active=True)
if not datastore.find_user(email="[email protected]"):
datastore.create_user(
name="Student 1",
email="[email protected]", password=generate_password_hash("pass123"), roles=["member"])
if not datastore.find_user(email="[email protected]"):
datastore.create_user(
name="Student 2",
email="[email protected]", password=generate_password_hash("pass123"), roles=["member"])
db.session.commit()