-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb_setup.py
More file actions
39 lines (26 loc) · 853 Bytes
/
db_setup.py
File metadata and controls
39 lines (26 loc) · 853 Bytes
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
# To Do
# Buraya ilk kurulum için ayarları gerçekleştirmeye yardım edecek bazı configler gelecek.
# Daha önceden kurulum yapılmışsa bunu çalıştırmak yerine yeni bir çözüm üretilebilir.
from werkzeug import generate_password_hash
from tracer.data.models import db, User, Role
from tracer import app
db.init_app(app)
def create_roles(ctx):
role = Role('admin')
ctx.session.add(role)
ctx.session.commit()
def create_user(ctx):
email = 'admin@admin'
name = 'John Doe'
password = generate_password_hash('admin')
is_active = True
roles = 1
user = User(
email=email, name=name, password=password, active=is_active, roles=roles)
ctx.session.add(user)
ctx.session.commit()
with app.app_context():
db.drop_all()
db.create_all()
create_roles(db)
create_user(db)