-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_init.py
72 lines (61 loc) · 1.43 KB
/
db_init.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# db init
from flask_security.utils import hash_password
from src import Role, User, app, db
from src.models import Email
from src.models.Application import Application
db.drop_all()
db.create_all()
u = User(
username="admin",
active=True,
name="admin 1",
address="lol",
country="e",
city="zz",
number="45445",
)
u2 = User(
username="user1",
active=True,
name="user 1",
address="lol",
country="e",
city="zz",
number="47445",
)
u3 = User(
username="user2",
active=True,
name="user 2",
address="lol",
country="e",
city="zz",
number="48445",
)
u.active = True
for a, u in enumerate([u, u2, u3]):
e = Email(label=f"user{a}@host.com")
e.is_primary = True
e.receive_notifications = True
u.email = e.label
u.emails.append(e)
r = Role(name="admin")
r1 = Role(name="user")
u.roles = [r, r1]
u2.roles = [r1]
u3.roles = [r1]
apps = [Application(name=f"app_{str(x)}", user=u, enabled=True) for x in range(1, 5)]
apps2 = [Application(name=f"app_{str(x)}", user=u2, enabled=True) for x in range(1, 5)]
# apps[0].enabled = True
# apps[0].entrypoint = "foobar.py"
# apps[0].domain_name = "app1.com"
with app.app_context():
u.password = hash_password("shift")
u2.password = hash_password("shift")
u3.password = hash_password("shift")
# for a in apps:
# db.session.add(a)
db.session.add(u)
db.session.add(u2)
db.session.add(u3)
db.session.commit()