-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_tables.py
39 lines (31 loc) · 1.04 KB
/
create_tables.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
31
32
33
34
35
36
37
38
39
import psycopg2
import configparser
from sql_queries import stagin_tables_queries, drop_tables_queries, dwh_tables_queries
# CONFIG
config = configparser.ConfigParser()
config.read('dwh.cfg')
ENDPOINT = config.get("CLUSTER", "ENDPOINT")
DBNAME = config.get("CLUSTER", "DBNAME")
USER = config.get("CLUSTER", "USER")
PASSWORD = config.get("CLUSTER", "PASSWORD")
PORT = config.get("CLUSTER", "PORT")
def drop_tables(conn, cur):
for query in drop_tables_queries:
cur.execute(query)
conn.commit()
def create_staging_tables(conn, cur):
for query in stagin_tables_queries:
cur.execute(query)
conn.commit()
def create_dwh_tables(conn, cur):
for query in dwh_tables_queries:
cur.execute(query)
conn.commit()
if __name__ == "__main__":
conn = psycopg2.connect("host={} dbname={} user={} password={} port={}".format(ENDPOINT, DBNAME, USER, PASSWORD, PORT
))
cur = conn.cursor()
drop_tables(conn, cur)
create_staging_tables(conn, cur)
create_dwh_tables(conn, cur)
conn.close()