From da69709b4da172e25f08730e26a079ecd88400d2 Mon Sep 17 00:00:00 2001 From: Jeremiah Boby Date: Sat, 26 Feb 2022 21:49:22 +0100 Subject: [PATCH] Add docs for scripts --- scripts/clean_db.py | 26 +++++++++++++++----------- scripts/fake/config.py | 1 + 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/clean_db.py b/scripts/clean_db.py index 8f96d07c..0d27a532 100644 --- a/scripts/clean_db.py +++ b/scripts/clean_db.py @@ -1,16 +1,20 @@ +"""Script for clearing the connected database of all data.""" + import os from os import getenv import psycopg2 -with psycopg2.connect( - user=getenv("SQL_USER"), - password=getenv("SQL_PASSWORD"), - host=getenv("SQL_HOST"), - port=getenv("SQL_PORT"), - database="template1", -) as connection: - connection.set_isolation_level(0) - with connection.cursor() as cursor: - cursor.execute(f"DROP DATABASE {os.getenv('SQL_DATABASE')}") - cursor.execute(f"CREATE DATABASE {os.getenv('SQL_DATABASE')}") + +if __name__ == '__main__': + with psycopg2.connect( + user=getenv("SQL_USER"), + password=getenv("SQL_PASSWORD"), + host=getenv("SQL_HOST"), + port=getenv("SQL_PORT"), + database="template1", + ) as connection: + connection.set_isolation_level(0) + with connection.cursor() as cursor: + cursor.execute(f"DROP DATABASE {os.getenv('SQL_DATABASE')}") + cursor.execute(f"CREATE DATABASE {os.getenv('SQL_DATABASE')}") diff --git a/scripts/fake/config.py b/scripts/fake/config.py index 732cd0b5..5c2c92c1 100644 --- a/scripts/fake/config.py +++ b/scripts/fake/config.py @@ -18,6 +18,7 @@ class PostgreSQL: @classproperty def dsn(cls) -> str: + """Return the DSN for connecting to the configured database.""" return f"postgres://{cls.USER}:{cls.PASSWORD}@{cls.HOST}:{cls.PORT}/template1"