2019-05-18 19:00:13 +02:00
|
|
|
from datetime import datetime
|
|
|
|
import pandas as pd
|
|
|
|
import numpy as np
|
|
|
|
from flask_script import Command
|
|
|
|
|
|
|
|
|
|
|
|
from app import db
|
2019-05-18 19:47:47 +02:00
|
|
|
from app.widget import Widget
|
|
|
|
from app.fizz.fizzbaz import Fizzbaz
|
|
|
|
from app.fizz.fizzbar import Fizzbar
|
|
|
|
from app.other_api.doodad import Doodad
|
|
|
|
from app.other_api.whatsit import Whatsit
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
|
2019-05-18 19:47:47 +02:00
|
|
|
def seed_things():
|
|
|
|
classes = [Widget, Fizzbaz, Fizzbar, Doodad, Whatsit]
|
|
|
|
for klass in classes:
|
|
|
|
seed_thing(klass)
|
|
|
|
|
|
|
|
|
|
|
|
def seed_thing(cls):
|
|
|
|
things = [
|
2019-05-18 19:00:13 +02:00
|
|
|
{
|
|
|
|
'name': 'Pizza Slicer',
|
|
|
|
'purpose': 'Cut delicious pizza',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'Rolling Pin',
|
|
|
|
'purpose': 'Roll delicious pizza',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'Pizza Oven',
|
|
|
|
'purpose': 'Bake delicious pizza',
|
|
|
|
},
|
|
|
|
]
|
2019-05-18 19:47:47 +02:00
|
|
|
db.session.bulk_insert_mappings(cls, things)
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
class SeedCommand(Command):
|
|
|
|
""" Seed the DB."""
|
|
|
|
|
|
|
|
def run(self):
|
2019-08-03 18:50:36 +02:00
|
|
|
if input('Are you sure you want to drop all tables and recreate? (y/N)\n'
|
2019-05-18 19:00:13 +02:00
|
|
|
).lower() == 'y':
|
|
|
|
print('Dropping tables...')
|
|
|
|
db.drop_all()
|
|
|
|
db.create_all()
|
2019-05-18 19:47:47 +02:00
|
|
|
seed_things()
|
2019-05-18 19:00:13 +02:00
|
|
|
db.session.commit()
|
2019-05-18 19:47:47 +02:00
|
|
|
print('DB successfully seeded.')
|