| import asyncio |
| import os |
| import sys |
|
|
| |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
|
|
| from app.config import settings |
| from app.services.appwrite_db import get_appwrite_db |
|
|
| async def add_audio_attribute(): |
| """ |
| Adds the 'audio_url' attribute to all article collections. |
| """ |
| print("="*60) |
| print("π Adding 'audio_url' attribute to Appwrite Collections") |
| print("="*60) |
| |
| appwrite = get_appwrite_db() |
| |
| if not appwrite.initialized: |
| print("β Appwrite not initialized. Check credentials.") |
| return |
|
|
| |
| collections = [ |
| settings.APPWRITE_COLLECTION_ID, |
| settings.APPWRITE_CLOUD_COLLECTION_ID, |
| settings.APPWRITE_AI_COLLECTION_ID, |
| settings.APPWRITE_DATA_COLLECTION_ID, |
| settings.APPWRITE_MAGAZINE_COLLECTION_ID, |
| settings.APPWRITE_MEDIUM_COLLECTION_ID |
| ] |
| |
| |
| |
| |
| for col_id in collections: |
| if not col_id or col_id == "change_me": |
| continue |
| |
| print(f"Checking collection: {col_id}...") |
| |
| try: |
| |
| |
| |
| |
| |
| |
| |
| try: |
| appwrite.databases.create_url_attribute( |
| database_id=settings.APPWRITE_DATABASE_ID, |
| collection_id=col_id, |
| key="audio_url", |
| required=False, |
| default=None |
| ) |
| print(f"β
Added 'audio_url' to {col_id}") |
| except Exception as e: |
| if "Attribute already exists" in str(e) or "409" in str(e): |
| print(f"β οΈ Attribute 'audio_url' already exists in {col_id}") |
| else: |
| print(f"β Failed to add attribute to {col_id}: {e}") |
|
|
| except Exception as e: |
| print(f"β Error processing collection {col_id}: {e}") |
|
|
| print("\nπ Schema update complete!") |
|
|
| if __name__ == "__main__": |
| asyncio.run(add_audio_attribute()) |
|
|