-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_create.py
38 lines (27 loc) · 1.73 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
#!/usr/bin/env python
"""
This script initializes and populates DB for manual testing.
"""
from mgorest.v1_0.models import User
from mgorest import db, app
users = [
dict(login='paul', password='paul1234', first_name='Paul', last_name='M.', occupation='Musician', city='London'),
dict(login='ritchie', password='ritch1234', first_name='Ritchie', last_name='B.', occupation='Musician', city='London'),
dict(login='bob', password='bob1234', first_name='Bob', last_name='N.', occupation='Actor', city='Los Angeles'),
dict(login='steve', password='steve1234', first_name='Steve', last_name='V.', occupation='Musician', city='Los Angeles'),
dict(login='amy', password='amy1234', first_name='Amy', last_name='B.', occupation='Musician', city='Los Angeles'),
dict(login='jason', password='jason1234', first_name='Jason', last_name='L.', occupation='Actor', city='Los Angeles'),
dict(login='David', password='david1234', first_name='David', last_name='G.', occupation='Musician', city='Los Angeles'),
dict(login='stanley', password='stanley1234', first_name='Stanley', last_name='T.', occupation='Actor', city='London'),
dict(login='peter', password='peter1234', first_name='Peter', last_name='T.', occupation='Actor', city='London'),
dict(login='kate', password='kate1234', first_name='Kate', last_name='L.', occupation='Actor', city='New York')
]
with app.app_context():
db.create_all()
for user in users:
user_entry = User() # Create new row in the table
for data_type in user: # go over attributes an set corresponding (same name) column in the table
setattr(user_entry, data_type, user[data_type])
db.session.add(user_entry)
db.session.commit()
print User.query.all()