Determines category for historical data, before category column

Im worried this might be slow, so let me know if you can think of a better way. It's an alembic script to loop through all the data that was added before the category column was added, then update the category column using the topic.