forked from ArkinDharawat/JournalTopicModel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_ddl.py
More file actions
33 lines (22 loc) · 719 Bytes
/
create_ddl.py
File metadata and controls
33 lines (22 loc) · 719 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
import logging
import os
import mysql.connector
import yaml
from SQLQueries.SQLStrQuery import SQLStrQuery
logger = logging.getLogger("ddl-script")
SQLStrObj = SQLStrQuery(10) # TODO: Change to global var
# Read YAML file
with open(os.path.join(os.getcwd(), "config.yml"), 'r') as stream:
config = yaml.safe_load(stream)
cnx = mysql.connector.connect(**config)
logger.info("Connected to SQL")
cursor = cnx.cursor()
logger.info("Created Cursor")
for ddl_query_str in SQLStrObj.create_tables():
cursor.execute(ddl_query_str)
logger.info("Created tables")
stored_procedure = SQLStrObj.create_procedure()
cursor.execute(stored_procedure)
cursor.close()
cnx.close()
logger.info("All Connections Closed")