-
Notifications
You must be signed in to change notification settings - Fork 1
/
db_create.py
48 lines (32 loc) · 1.71 KB
/
db_create.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
from app import db
from app.models import Recipe, User
# drop existing database tables
print 'Dropping existing database tables...'
db.drop_all()
# create the database and the database tables
print 'Creating database tables...'
db.create_all()
# insert user data
admin_user=User(email='[email protected]', plaintext_password='adminpassword', role='admin')
user1=User(email='[email protected]', plaintext_password='password123', role='user')
user2=User(email='[email protected]', plaintext_password='ovacodol', role='user')
user3=User(email='[email protected]', plaintext_password='password', role='user')
user4=User(email='[email protected]', plaintext_password='oldpassword', role='user')
# add users to db
print 'Inserting user data...'
db.session.add_all([admin_user, user1, user2, user3, user4])
# insert recipe data: title, description, user_id, is_public
# recipe1=Recipe('Omena', 'Omena cooked with onion and pepper.', False, admin_user.id)
# recipe2=Recipe('Scrambled Eggs', 'Eggs fried with onions, tomatoes, and green peppers.', True, admin_user.id)
# recipe3=Recipe('Chicken Biriani', 'Stewed chicken in spices.', True, user1.id)
# recipe4=Recipe('Kamande', 'Fried lentils in onions and spices', True, user3.id)
recipe1=Recipe('Omena', 'Omena cooked with onion and pepper.', admin_user.id, False)
recipe2=Recipe('Scrambled Eggs', 'Eggs fried with onions, tomatoes, and green peppers.', admin_user.id, True)
recipe3=Recipe('Chicken Biriani', 'Stewed chicken in spices.', user1.id, True)
recipe4=Recipe('Kamande', 'Fried lentils in onions and spices', user3.id, True)
# add recipes to db
print 'Inserting recipe data...'
db.session.add_all([recipe1, recipe2, recipe3, recipe4])
# commit the changes
db.session.commit()
print 'Done!'