-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumpPostgresQLSchema.py
32 lines (22 loc) · 1.04 KB
/
dumpPostgresQLSchema.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
import psycopg2
# ORIGIN ***************************************************************************
connOrigin = psycopg2.connect(database="mine", user="GK47LX", host="localhost", port="5432")
curOrigin = connOrigin.cursor()
with open("blahOrigin.csv", "w") as f:
curOrigin.copy_expert(f"COPY ALPHA.BLAH TO STDOUT WITH HEADER CSV", f)
with open("rolesOrigin.csv", "w") as f:
curOrigin.copy_expert(f"COPY ALPHA.ROLES TO STDOUT WITH HEADER CSV", f)
curOrigin.close()
connOrigin.close()
# DESTINATION **********************************************************************
connDest = psycopg2.connect(database="mine", user="GK47LX", host="localhost", port="5432")
curDest = connDest.cursor()
curDest.execute("delete from DELTA.BLAH")
with open("blahOrigin.csv", "r") as f:
curDest.copy_expert(f"COPY DELTA.BLAH FROM STDIN WITH HEADER CSV", f)
curDest.execute("delete from DELTA.ROLES")
with open("rolesOrigin.csv", "r") as f:
curDest.copy_expert(f"COPY DELTA.ROLES FROM STDIN WITH HEADER CSV", f)
connDest.commit()
curDest.close()
connDest.close()