def setUp(self) -> None: self.app = create_app("testing") self.client = self.app.test_client() self.app.app_context().push() db.create_all() self.book_data = json.dumps({ "title": "Single Book", "author": "Book author", "price": 200 }) self.headers = {"Content-Type": "application/json"}
def run(self): if self.args.producer_class_name: self.p.run_by_class_name(self.args.producer_class_name) elif self.args.consumer_class_name: self.s.run_by_class_name(self.args.consumer_class_name) elif self.args.run_all_producer: self.p.run_all() elif self.args.migrate: db.create_all() else: self.s.start() self.p.start()
#! /usr/bin/env python2 # encoding: utf8 import py_path from utils.db import create_all, _database if __name__ == "__main__": if not raw_input( "Are you shure you want to create database?[yes/no]: ") == 'yes': exit(0) print "Creating database with default alias in global settings..." ## Init session session = _database._get_db_session() ## Import and create all models: create_all(dirpath='models')
def db_init(allergo_file, recipes_file): ''' initialize a db ''' db.create_all() fill_allergies(allergo_file) fill_recipes(recipes_file)
from sqlalchemy import create_engine, exc import tables from utils import db """ This simple script takes care of the MySQL set-up. """ engine = create_engine("mysql://localhost/mysql") conn = engine.connect() conn.execute("COMMIT") try: conn.execute("CREATE DATABASE sobbingrabbit") except exc.ProgrammingError: print("exists") conn.close() db.create_all()
""" Add tzinfo if not available Assuming the column always use UTC timezone """ impl = TIMESTAMP(timezone=True) def process_result_value(self, value, dialect): if value and not value.tzinfo: value = value.replace(tzinfo=timezone.utc) return value class RSSNotification(db.Base): __tablename__ = 'rss_notifications' id = Column(Integer, primary_key=True) user_id = Column(String, nullable=False, index=True) chat_id = Column(String) rss_url = Column(Text, nullable=False) last_item_date = Column(TimeStamp) class TradingPortfolio(db.Base): __tablename__ = 'trading_portfolios' id = Column(Integer, primary_key=True) user_id = Column(String, nullable=False, index=True) chat_id = Column(String) data = Column(JSON, nullable=True) db.create_all(db.Base, db.engine)
def clear_db(): db.session.commit() db.drop_all() db.create_all()
def initdb(): """Creates all database tables.""" db.create_all()