mirror of
https://github.com/wahyd4/links.git
synced 2026-08-08 21:04:53 +10:00
fix: migration must update existing ask LINK record (backup old chatgpt link)
Prod had an old ask link (LINK → chatgpt.com, id=235). get_or_create would leave it as LINK, so go/ask/问题 would redirect to chatgpt instead of sending to Discord. Switch to update_or_create and back up the old chatgpt link to alias ask-chatgpt.
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user