Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add simple script to check uid duplicates in db #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions DHIS2/find_duplicates_in_db/duplicate_uids_in_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import psycopg2

con = psycopg2.connect(database="", user="", password="", host="127.0.0.1", port="5434")
print("Database opened successfully")

cur = con.cursor()

cur.execute("select t.table_schema, t.table_name from information_schema.tables t inner join information_schema.columns c on c.table_name = t.table_name and c.table_schema = t.table_schema where c.column_name = 'uid' and t.table_schema not in ('information_schema', 'pg_catalog') and t.table_type = 'BASE TABLE' order by t.table_schema;");

rows = cur.fetchall()
tables = []


for row in rows:
tables.append(row[1])
for table in tables:
if table in ["audit", "deletedobject", "visualization"]:
continue
print(table)
cur.execute("select uid from "+table+";");
rows = cur.fetchall()
active_uid = []
for row in rows:
active_uid.append(row[0])
for tableB in tables:
if tableB in ["audit", "deletedobject", "visualization"]:
continue
if tableB != table:
cur.execute("select uid from "+tableB+";");
rows = cur.fetchall()
for row in rows:
if row[0] in active_uid:
print ({"id": row[0], "typeA": table, "typeB": tableB},)


con.close()