forked from sdslabs/muzi-scanner-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createdb.py
30 lines (26 loc) · 1.16 KB
/
createdb.py
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 schema import Base
from sqlalchemy import create_engine
from sqlalchemy_utils import database_exists, create_database, drop_database
import credentials
db_name = credentials.get_db_name()
db_user_name = credentials.get_db_user_name()
db_host = credentials.get_db_host()
db_password = credentials.get_db_password()
db_backend = credentials.get_db_backend()
# later, we create the engine
engine = create_engine('{backend}://{user}:{password}@{host}/{name}'.format(backend=db_backend,
user=db_user_name,
password=db_password,
host=db_host,
name=db_name))
if __name__ == '__main__':
# create db if it doesn't exist
if database_exists(engine.url):
print 'Database already exists.'
exit()
try:
create_database(engine.url)
Base.metadata.create_all(engine)
print "Database created."
except Exception as e:
print str(e)