lty/qy_lty/aiapp/migrations/0003_create_rtc_bot.py
pmc 29b4913723
All checks were successful
Build and Deploy LTY / build-and-deploy (push) Successful in 9m19s
feat: update RTC bot migration and device interaction consumers
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 18:08:05 +08:00

33 lines
914 B
Python

from django.db import migrations
def create_rtc_bot(apps, schema_editor):
Bot = apps.get_model('aiapp', 'Bot')
if not Bot.objects.filter(name='RTC_Voice_Agent').exists():
# 手动指定一个不会冲突的 id
from django.db import connection
with connection.cursor() as cursor:
cursor.execute("SELECT COALESCE(MAX(id), 0) + 1 FROM aiapp_bot")
next_id = cursor.fetchone()[0]
Bot.objects.create(
id=next_id,
name='RTC_Voice_Agent',
description='RTC实时语音智能体'
)
def remove_rtc_bot(apps, schema_editor):
Bot = apps.get_model('aiapp', 'Bot')
Bot.objects.filter(name='RTC_Voice_Agent').delete()
class Migration(migrations.Migration):
dependencies = [
('aiapp', '0002_initial'),
]
operations = [
migrations.RunPython(create_rtc_bot, remove_rtc_bot),
]