2021-10-10 10:32:28 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import logging
|
|
|
|
import asyncio
|
2022-04-02 18:43:20 +00:00
|
|
|
import argparse
|
2021-10-10 10:32:28 +00:00
|
|
|
|
2022-04-02 18:43:20 +00:00
|
|
|
from obs.api.db import drop_all, init_models, connect_db
|
2021-11-17 17:33:28 +00:00
|
|
|
from obs.api.app import app
|
2021-10-10 10:32:28 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
2022-04-02 18:43:20 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="drops the whole database, and possibly creates new table schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-s",
|
|
|
|
"--create-schema",
|
|
|
|
action="store_true",
|
|
|
|
help="create the schema",
|
|
|
|
)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2021-10-10 10:32:28 +00:00
|
|
|
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s: %(message)s")
|
|
|
|
|
2021-11-17 17:33:28 +00:00
|
|
|
async with connect_db(app.config.POSTGRES_URL):
|
2022-04-02 18:43:20 +00:00
|
|
|
await drop_all()
|
|
|
|
if args.create_schema:
|
|
|
|
await init_models()
|
2021-10-10 10:32:28 +00:00
|
|
|
log.info("Database initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
asyncio.run(main())
|