from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base
import os

# create the connection to the database
engine = create_engine(os.environ["DATABASE_URL"])
db = scoped_session(sessionmaker(autoflush=True, bind=engine))

Base = declarative_base()
Base.query = db.query_property()


def init_db(drop_all=False):
    """Initialize the database, optionally dropping existing tables."""
    if drop_all:
        Base.metadata.drop_all(bind=engine)
    Base.metadata.create_all(bind=engine)
    return db

@@ -197,57 +197,153 @@
 ase%0A
-engine = create_engine(os.environ%5B%22DATABASE_URL%22%5D
+if %22DATABASE_URL%22 in os.environ:%0A    db_url = os.environ%5B%22DATABASE_URL%22%5D%0Aelse:%0A    db_url = %22sqlite:///wallace.db%22%0A%0Aengine = create_engine(db_url
 )%0Adb

Use SQLite placeholder if db URL not specified