def install_models(): orm.configure_mappers() db.create_all() db.session.commit() if IS_DEV: install_models_data()
def install_models(): orm.configure_mappers() create_versionning_tables() db.create_all() db.session.commit()
def setUp(self): self.app = self.create_app() self.client = self.app.test_client(use_cookies=True) try: db.create_all() except Exception as e: print(e) self.create_user() # create_admin mainly for supportside testing time.sleep(0.1) self.create_admin() users = db.session.query(Users).order_by(Users.create_timestamp).all() user = users[0] self.user = user admin = users[1] self.admin = admin
def app(info): # Use the variable the defined outside the closure. nonlocal flask_app_context # Create flask application. flask_app = create_app(test_env=True) # Create application context flask_app_context = flask_app.app_context() # Push it onto the context stack. flask_app_context.push() # Create the tables. db.create_all() return flask_app
def initialize_db(app): """ Fixture for creating tables in the database. Drops tables after each function. Args: app (Flask): a flask application instance. """ # Create tables db.create_all() yield app # Close connection. Postgres needs it to release locks db.session.close() # Drop all tables db.drop_all()
# GitHub API if not app.config.get('GITHUB_CLIENT_ID') or not app.config.get( 'GITHUB_CLIENT_SECRET'): logger.error( 'Set GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET in .env or environment variables' ) sys.exit(-1) github.client_id = app.config['GITHUB_CLIENT_ID'] github.client_secret = app.config['GITHUB_CLIENT_SECRET'] # SQLAlchemy (needs to be run on import for pythonanywhere) db.app = app db.init_app(app) # create database tables for models with app.app_context(): db.create_all() @app.template_filter() def datetimesince(datestr): """Returns the difference between the given datetime string and now as text. E.g. 13 minutes ago """ try: if isinstance(datestr, str): datestr = dt.parse(datestr) now = datetime.now(timezone.utc) diff = now - datestr d = diff.days // 365 if d > 0:
from models.flow import Flow # exceptions from mage_exceptions import NoConnectedDevice, \ NoConnectedBridge, \ UserException, \ UnableToConnect, \ DBException from requests.exceptions import Timeout, \ ConnectionError, \ TooManyRedirects, \ HTTPError import logging logger = logging.getLogger(__name__) db.create_all() class Controller(object): def __init__(self, hostname): assert hostname is not None assert hostname is not '' self.hostname = hostname self.port = 5000 self.protocol = "http" self.markup = "json" self.headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} def _get_grequests(self, ipAddresses, endpoint): urls = [] for ip in ipAddresses: self.hostname = ip
def install_models(): orm.configure_mappers() db.create_all() db.session.commit()
import connexion from connexion.resolver import RestyResolver from models.db import db, configureAppForDB if __name__ == '__main__': connexionApp = connexion.App(__name__, specification_dir='swagger/') connexionApp.add_api('v1.yaml', resolver=RestyResolver('api.v1')) # Configure MongoEngine # app here is the Flask instance configureAppForDB(connexionApp.app) db.init_app(connexionApp.app) db.create_all(app=connexionApp.app) connexionApp.run(port=9090)
def drop_post_table() -> None: try: Post.__table__.drop(db.engine) except: pass db.create_all()
def exec_server(): logger.info("Starting") db.create_all() logger.info("Created database")
def db_create_all(): db.create_all() db.session.commit()