Add telegram_communication app with dedicated DB routing
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s

- Register TelegramCommunicationConfig in INSTALLED_APPS and add telegram_db to DATABASES
- Define TelegramData model mapped to the messages table
- Fix allow_migrate in ProjectDatabaseRouter: redirect and telegram entries were returning the DB name string (always truthy) instead of a boolean comparison, causing their migrations to bleed into every database
- Add telegram routing to db_for_read, db_for_write, allow_relation, and allow_migrate

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-30 13:20:40 +01:00
co-authored by Claude Sonnet 4.6
parent ec2696ee43
commit b4545d6c99
7 changed files with 92 additions and 6 deletions
+10 -4
View File
@@ -16,6 +16,8 @@ class ProjectDatabaseRouter:
return 'redirect_db'
if model._meta.app_label == 'cloudmanager':
return 'cloudmanager_db'
if model._meta.app_label == 'telegram':
return 'telegram_db'
return 'default'
def db_for_write(self, model, **hints):
@@ -28,14 +30,16 @@ class ProjectDatabaseRouter:
return 'cloudmanager_db'
if model._meta.app_label == 'redirect':
return 'redirect_db'
if model._meta.app_label == 'telegram':
return 'telegram_db'
return 'default'
def allow_relation(self, obj1, obj2, **hints):
"""Allow relations if both models are in the same database."""
# Prevents accidental foreign key relationships across different physical DBs
if (
obj1._meta.app_label in ['simpsons', 'cloudmanager','redirect','job'] or
obj2._meta.app_label in ['simpsons', 'cloudmanager','redirect','job']
obj1._meta.app_label in ['simpsons', 'cloudmanager','redirect','job','telegram'] or
obj2._meta.app_label in ['simpsons', 'cloudmanager','redirect','job','telegram']
):
return obj1._meta.app_label == obj2._meta.app_label
return None
@@ -49,9 +53,11 @@ class ProjectDatabaseRouter:
if app_label == 'cloudmanager':
return db == 'cloudmanager_db'
if app_label == 'redirect':
return 'redirect_db'
return db == 'redirect_db'
if app_label == 'telegram':
return db == 'telegram_db'
# Ensure default Django apps (auth, sessions, etc.) don't migrate into simpsons/cloudmanager
if db in ['simpsons_db', 'cloudmanager_db','redirect_db','job_db']:
if db in ['simpsons_db', 'cloudmanager_db','redirect_db','job_db','telegram_db']:
return False
return None