in glam/api/management/commands/import_user_counts.py [0:0]
def import_file(self, tmp_table, fp):
csv_columns = [
f.name for f in FirefoxCounts._meta.get_fields() if f.name not in ["id"]
]
conflict_columns = [
f
for f in FirefoxCounts._meta.constraints[0].fields
if f not in ["id", "total_users"]
]
log(" Importing file into temp table.")
with connection.cursor() as cursor:
with open(fp.name, "r") as tmp_file:
sql = "COPY {tmp_table} ({columns}) FROM STDIN WITH CSV".format(
tmp_table=tmp_table, columns=", ".join(csv_columns)
)
cursor.copy_expert(sql, tmp_file)
log(" Inserting data from temp table into aggregation tables.")
with connection.cursor() as cursor:
sql = """