Read reset_database config (POSTGRES_URL) from app

This commit is contained in:
Paul Bienkowski 2021-11-17 18:33:28 +01:00
parent 131afd5adc
commit b6aa0cb1c9

View file

@ -1,10 +1,9 @@
#!/usr/bin/env python3
import argparse
import logging
import os
import asyncio
from obs.api.db import init_models, connect_db
from obs.api.app import app
log = logging.getLogger(__name__)
@ -12,23 +11,7 @@ log = logging.getLogger(__name__)
async def main():
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s: %(message)s")
parser = argparse.ArgumentParser(
description="clears the postgresql database and initializes the schema"
)
# https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
postgres_url_default = os.environ.get("POSTGRES_URL")
parser.add_argument(
"--postgres-url",
required=postgres_url_default is None,
action="store",
help="connection string for postgres database, if set, the track result is imported there",
default=postgres_url_default,
)
args = parser.parse_args()
async with connect_db(args.postgres_url):
async with connect_db(app.config.POSTGRES_URL):
await init_models()
log.info("Database initialized.")