-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_config.py
More file actions
43 lines (32 loc) · 909 Bytes
/
db_config.py
File metadata and controls
43 lines (32 loc) · 909 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
31
32
33
34
35
36
37
38
39
40
41
42
43
import psycopg2
import os
from app.api.v2.models.db_model import Database
from instance.config import app_config
env = os.getenv('FLASK_ENV')
url = app_config[env].DATABASE_URL
def db_connection():
"""Create Database Connection"""
connection = psycopg2.connect(url)
return connection
def create_tables():
"""Creates the Tables"""
connection = db_connection()
cursor = connection.cursor()
database = Database()
queries = database.db_query()
for sql in queries:
cursor.execute(sql)
connection.commit()
cursor.close()
def create_super_admin():
"""create a default admin"""
try:
connection = db_connection()
cursor = connection.cursor()
database = Database()
sql = database.add_admin()
cursor.execute(sql)
connection.commit()
cursor.close()
except:
return 'user exists'