-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrations.py
40 lines (34 loc) · 1.11 KB
/
migrations.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
from models import db, Contact, User, Remarks, Att, Attendance, Att_T, Allow
from werkzeug.security import generate_password_hash, check_password_hash
# db.drop_all()
db.create_all()
users = User.query.all()
batches = Contact.query.with_entities(Contact.batch).distinct()
for user in users:
for a in batches:
new_allow = Allow(
user=user.username,
allowed=a[0]
)
db.session.add(new_allow)
db.session.commit()
# all = Contact.query.order_by(Contact.fullname).all()
# for i in all:
# Add_Att_T = Att_T(
# present = Att.query.filter_by(of = i.fullname ,status=True).count(),
# absent = Att.query.filter_by(of = i.fullname , status= False).count(),
# uid = i.uid
# )
# db.session.add(Add_Att_T)
# db.session.commit()
# Default User
hashed_password = generate_password_hash('1234', method='sha256')
new_user = User(
adid='DefaultUser',
username='Admin',
email='[email protected]',
admin=True,
userad=True,
password=hashed_password)
db.session.add(new_user)
db.session.commit()