def setup_database(_app): # {{{ """Add some sample data to database""" with _app.app_context(): _app.logger.info('Creating databases') DB.drop_all() # TODO do not drop all data on restart DB.create_all() DB.session.commit() _app.logger.info('Created databases') example_game = Game.query.filter_by(game_ext_id='BASEMENT').first() if example_game is None: _app.logger.info('Creating example game') example_game = Game(game_ext_id='BASEMENT') DB.session.add(example_game) DB.session.commit() for i in range(5): test_playersession = PlayerSession( username='******'.format(num=i), session_key=gen_session_key(), game_id=example_game.id) DB.session.add(test_playersession) DB.session.commit() _app.logger.info('Created test game and playersessions')
def setup_database(_app): # {{{ """Add some sample data to database""" with _app.app_context(): _app.logger.info('Creating databases') DB.drop_all() # TODO DB.create_all() DB.session.commit() _app.logger.info('Created databases') example_user = User.query.filter_by(username='******').first() if example_user is None: _app.logger.info('Creating test user') example_user = User(username='******', email='*****@*****.**', password_hash=hash_password('asdf')) DB.session.add(example_user) DB.session.commit() example_item = Item.query.filter_by(user_id=example_user.id).first() if example_item is None: _app.logger.info('Creating test item') example_item = Item(user_id=example_user.id, name='Test', purchase_price=123, sell_price=2345) DB.session.add(example_item) example_item_two = Item(user_id=example_user.id, name='Test2', purchase_price=23, sell_price=5678) DB.session.add(example_item_two) example_item_three = Item(user_id=example_user.id, name='Test3', purchase_price=1235, sell_price=778) DB.session.add(example_item_three) DB.session.commit() example_picture = Picture.query.filter_by( item_id=example_item.id).first() if example_picture is None: _app.logger.info('Creating test picture') example_picture = Picture(item_id=example_item.id, path='http://reddit.com') DB.session.add(example_picture) DB.session.commit() example_location = Location.query.filter_by( name='Freelton Market').first() if example_location is None: _app.logger.info('Creating test location') example_location = Location(name='Freelton Market', user_id=example_user.id) DB.session.add(example_location) DB.session.commit() _app.logger.info('Created test user, item, picture and location')
def setup_database(_app): # {{{ """Add some sample data to database""" with _app.app_context(): _app.logger.info('Creating databases') DB.drop_all() # TODO do not drop all data on restart DB.create_all() DB.session.commit() _app.logger.info('Created databases') example_account = Account.query.filter_by(device_key='exampleaccount').first() if example_account is None: _app.logger.info('Creating example account') example_account = Account(device_key='exampleaccount') DB.session.add(example_account) DB.session.commit() test_accounts = [Account()] * 5 # five test accounts for i, _ in enumerate(test_accounts): test_accounts[i] = Account.query.filter_by(device_key='testaccount{i}'.format(i=i)).first() if test_accounts[i] is None: test_accounts[i] = Account(device_key='testaccount{i}'.format(i=i)) DB.session.add(test_accounts[i]) DB.session.commit() example_event = Event.query.filter_by(account_id=example_account.id).first() if example_event is None: _app.logger.info('Creating test event') example_event = Event(account_id=example_account.id, latitude=32.079663, longitude=34.775528, group_size_max=3, group_size_min=1, title="Isreal is real", category="Social", time=datetime.datetime.utcnow(), description="Let us come together in peace. 3 hypes") DB.session.add(example_event) DB.session.commit() for i in range(3): DB.session.add(Hype(account_id=test_accounts[i].id, event_id=example_event.id)) DB.session.add(Checkin(account_id=test_accounts[i].id, event_id=example_event.id)) example_event_two = Event(account_id=example_account.id, latitude=43.545199, longitude=-80.246926, group_size_max=5, group_size_min=3, title="Trappers halloween costume party", category="Social drinking", time=datetime.datetime.utcnow(), description="BYOB costume party. Hawaiian theme. 5 hypes") DB.session.add(example_event_two) DB.session.commit() for i in range(5): DB.session.add(Hype(account_id=test_accounts[i].id, event_id=example_event_two.id)) DB.session.add(Checkin(account_id=test_accounts[i].id, event_id=example_event_two.id)) example_event_three = Event(account_id=example_account.id, latitude=43.530793, longitude=-80.229077, group_size_max=1, group_size_min=1, title="LAN party in Reynolds!", category="Sports", time=datetime.datetime.utcnow(), description="Bring a laptop and Halo CE for the LAN party. 3 hypes") DB.session.add(example_event_three) DB.session.commit() for i in range(3): DB.session.add(Hype(account_id=test_accounts[i].id, event_id=example_event_three.id)) DB.session.add(Checkin(account_id=test_accounts[i].id, event_id=example_event_three.id)) example_event_four = Event(account_id=example_account.id, latitude=43.531793, longitude=-80.228077, group_size_max=1, group_size_min=1, title="Vapers anonymous", category="Social", time=datetime.datetime.utcnow(), description="0 hypes") DB.session.add(example_event_four) DB.session.commit() _app.logger.info('Created test account and events')