-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_db.py
More file actions
30 lines (19 loc) · 726 Bytes
/
create_db.py
File metadata and controls
30 lines (19 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from psycopg2 import connect, DatabaseError
from connection_info import connection_info
def create_database():
drop_db_query = """DROP DATABASE IF EXISTS message_app_db;"""
create_db_query = """CREATE DATABASE message_app_db
ENCODING 'UTF-8';"""
create_database_info = {key: connection_info[key] for key in connection_info if key != 'database'}
try:
conn = connect(**create_database_info)
conn.autocommit = True
cur = conn.cursor()
cur.execute(drop_db_query)
cur.execute(create_db_query)
cur.close()
conn.close()
except DatabaseError as error:
print(error)
if __name__ == '__main__':
create_database()