-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_seeddb.py
More file actions
64 lines (43 loc) · 1.16 KB
/
cmd_seeddb.py
File metadata and controls
64 lines (43 loc) · 1.16 KB
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
from datetime import datetime, timedelta
import unittest
from app.app import create_app
from app.extensions import db
from app.models import User, Post
from config.setting import DevConfig
# Create an app context for the database connection.
app = create_app(DevConfig)
app_context = app.app_context()
app_context.push()
def init():
"""
Initialize the database.
:param with_testdb: Create a test database
:return: None
"""
db.drop_all()
db.create_all()
return None
def seed():
"""
Seed the database with an initial user.
:return: User instance
"""
if User.find_by_identity(app.config['SEED_ADMIN_EMAIL']) is not None:
return None
# Create new entries in the database
admin = User(app.config['SEED_ADMIN_EMAIL'],"admin",app.config['SEED_ADMIN_PASSWORD'],True)
db.session.add(admin)
db.session.commit()
return True
def main():
print("initializing")
init()
print("seeding")
if seed() == True :
print("Sucess")
elif seed () == None:
print("Already created ")
else:
print("Error")
if __name__ == "__main__":
main()