-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage.py
59 lines (50 loc) · 1.58 KB
/
manage.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
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/env python
from random import randint
from flask_script import Manager
from app.config import Config
from flask_migrate import Migrate, MigrateCommand
from app import app, db
from faker import Faker
from app.models import *
app.config['SQLALCHEMY_DATABASE_URI'] = Config.SQLALCHEMY_DATABASE_URI
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
fake = Faker()
@manager.command
def seed():
"""
Populates the database with dummy records
"""
print('seeding...')
users = []
bucketlists = []
bucketlist_items = []
# create 10 users
print('\tCreating users...')
for i in range(10):
users.append(Users(fake.first_name(), password='password'))
db.session.bulk_save_objects(users)
db.session.commit()
print('\tCreating users complete!')
# create BucketLists
countries = []
for i in range(100):
countries.append(fake.country())
bucketlists = [BucketList(title=country, created_by=(1, 21))
for country in set(countries)]
db.session.bulk_save_objects(bucketlists)
db.session.commit()
print('\tCreating bucketlist items complete!')
# create BucketListItem
names = []
for i in range(1000):
names.append(fake.name())
bucketlist_items = [BucketListItems(
item_name=name, bucketlist_id=randint(88, 168)) for name in set(names)]
db.session.bulk_save_objects(bucketlist_items)
db.session.commit()
print('\tCreating bucketlist items complete!')
print('Seeding complete!')
if __name__ == '__main__':
manager.run()