-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fab5b1
commit da69709
Showing
2 changed files
with
16 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters