diff --git a/migrations/20240327_add_created_table.py b/migrations/20240327_add_created_table.py index cc417cc2cd1c012d372ecb34c1131779763848e4..3b5c9c412c330db51a5776d29fa9aec2a4580f6a 100644 --- a/migrations/20240327_add_created_table.py +++ b/migrations/20240327_add_created_table.py @@ -19,7 +19,6 @@ def upgrade(): csv_filename = "./migrations/account-registration-history.csv" db = dataset.connect(f"sqlite:///{db_path}/{db_name}") - table = db["users"] # Get all username and last_update usernames = db.query("SELECT username, last_update FROM users") @@ -47,12 +46,13 @@ def upgrade(): "source": row[2], } - # Create new columns - table.create_column("date", db.types.datetime) - table.create_column("source", db.types.text) + data_types = dict( + username=db.types.text, date=db.types.datetime, source=db.types.text + ) - # Update database in chunk - table.update_many(list(users.values()), ["username"], ensure=True) + # Insert into database in chunks + table = db["user_created"] + table.insert_many(list(users.values()), ensure=True, types=data_types) if __name__ == "__main__":