update scripts to use Postgres
This commit is contained in:
@@ -23,12 +23,12 @@ def copy_data(postgres_conn, data_file: Path, log):
|
||||
log.info("read json file")
|
||||
with open(data_file, 'r') as json_file:
|
||||
json_load = json.load(json_file)
|
||||
postgres_cursor.execute("SET session_replication_role='replica'")
|
||||
for table in json_load:
|
||||
log.info(f"{table}: {len(json_load[table])}")
|
||||
# result[table] = import_table(table, json_load[table])
|
||||
truncate_statement = 'TRUNCATE {}'.format(table)
|
||||
truncate_statement = 'TRUNCATE {} CASCADE'.format(table)
|
||||
#log.info(f"truncate: {truncate_statement}")
|
||||
postgres_cursor.execute("SET FOREIGN_KEY_CHECKS = 0")
|
||||
postgres_cursor.execute(truncate_statement)
|
||||
items = json_load[table]
|
||||
for item in items:
|
||||
@@ -47,7 +47,7 @@ def copy_data(postgres_conn, data_file: Path, log):
|
||||
postgres_conn.commit()
|
||||
except psycopg2.Error as error:
|
||||
log.info('insert failed with %s', error)
|
||||
|
||||
postgres_cursor.execute("SET session_replication_role='origin'")
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = get_logger(args.verbose, args.config)
|
||||
|
||||
Reference in New Issue
Block a user