diff --git a/tildes/alembic/versions/468cf81f4a6b_topic_schedule_add_latest_topic_id.py b/tildes/alembic/versions/468cf81f4a6b_topic_schedule_add_latest_topic_id.py index 8f0384e..61f118d 100644 --- a/tildes/alembic/versions/468cf81f4a6b_topic_schedule_add_latest_topic_id.py +++ b/tildes/alembic/versions/468cf81f4a6b_topic_schedule_add_latest_topic_id.py @@ -28,6 +28,16 @@ def upgrade(): ["topic_id"], ) + op.execute( + """ + update topic_schedule set latest_topic_id = ( + select topic_id from topics + where schedule_id = topic_schedule.schedule_id + order by created_time desc limit 1 + ) + """ + ) + op.execute( """ create or replace function update_topic_schedule_latest_topic_id() returns trigger as $$