diff --git a/links/migrations/0053_ask_as_action_link.py b/links/migrations/0053_ask_as_action_link.py index 4e7e156..09ddaff 100644 --- a/links/migrations/0053_ask_as_action_link.py +++ b/links/migrations/0053_ask_as_action_link.py @@ -15,7 +15,19 @@ DISCORD_BOT_ID = '1467845106831855796' def create_ask_action_link(apps, schema_editor): Link = apps.get_model('links', 'Link') - Link.objects.get_or_create( + # 若旧 ask 是 LINK 类型(如指向 chatgpt 的快速提问链接),先备份到 ask-chatgpt + old = Link.objects.filter(alias='ask').first() + if old and old.link_type == 'LINK' and old.original_url: + if not Link.objects.filter(alias='ask-chatgpt').exists(): + Link.objects.create( + alias='ask-chatgpt', + link_type='LINK', + original_url=old.original_url, + description=(old.description or 'Quick ask chatgpt') + ' (原 ask 备份)', + ) + # update_or_create:生产库可能已有 ask 记录(旧版可能是 LINK 类型), + # 必须更新为 ACTION 类型 + discord_send 配置,否则 go/ask/问题 会走 LINK 分支失败。 + Link.objects.update_or_create( alias='ask', defaults={ 'link_type': 'ACTION', @@ -31,6 +43,7 @@ def create_ask_action_link(apps, schema_editor): def remove_ask_action_link(apps, schema_editor): Link = apps.get_model('links', 'Link') Link.objects.filter(alias='ask', link_type='ACTION').delete() + Link.objects.filter(alias='ask-chatgpt', description__endswith='(原 ask 备份)').delete() class Migration(migrations.Migration):