Create main and test database if it does not exist. Requires superuser.
Prototype:
def create():
"Create configured database if it does not exist"
name = app.config["DB_NAME"]
url = get_url(app.config["DB_USER"], app.config["DB_PASSWORD"],
app.config["DB_HOST"], app.config["DB_PORT"], "postgres")
engine = sqlalchemy.create_engine(url)
with engine.connect() as conn:
result = conn.execute(
"SELECT 1 FROM pg_catalog.pg_database WHERE datname='{}'"
.format(name))
if not result.first():
conn.execute("COMMIT")
conn.execute("CREATE DATABASE {}".format(name))
Create main and test database if it does not exist. Requires superuser.
Prototype: