From a58a457afa6cc9112b0a05f48b185c955bd58c94 Mon Sep 17 00:00:00 2001
From: Bo-Chun Louis Chen <louistw@uab.edu>
Date: Tue, 16 Apr 2024 15:04:36 -0500
Subject: [PATCH] Rename column in first loop

---
 migrations/20240327_add_created_table.py | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/migrations/20240327_add_created_table.py b/migrations/20240327_add_created_table.py
index cba1b31..78f78c1 100644
--- a/migrations/20240327_add_created_table.py
+++ b/migrations/20240327_add_created_table.py
@@ -25,7 +25,11 @@ def upgrade():
     usernames = db.query("SELECT username, last_update FROM users")
     users = {}
     for u in usernames:
-        users[u["username"]] = dict(u)
+        users[u["username"]] = {
+            "username": u["username"],
+            "date": fromisoformat(u["last_update"]),
+            "source": "account-web",
+        }
 
     # Get created from csv file
     with open(csv_filename) as f:
@@ -37,16 +41,6 @@ def upgrade():
                 users[row[0]]["date"] = fromisoformat(row[1])
                 users[row[0]]["source"] = row[2]
 
-    # Add copy created column from last_update if they are not in csv file
-    for username in users:
-        if "created" not in users[username]:
-            users[username]["date"] = fromisoformat(
-                users[username]["last_update"]
-            )
-            users[username]["source"] = "account-web"
-        # No need to update this column back to the db
-        del users[username]["last_update"]
-
     # Create new columns
     table.create_column("date", db.types.datetime)
     table.create_column("source", db.types.text)
-- 
GitLab