Spaces:
Sleeping

File size: 1,490 Bytes
cd61bf7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Apply Meta Channels Migration.
Adds whatsapp_config and instagram_config to tenants table.
"""

import asyncio
from sqlalchemy import text
from app.core.database import async_engine


async def apply_migration():
    """Apply the meta channels migration."""
    
    migration_sql = """
    -- Add WhatsApp and Instagram configuration columns to tenants table
    
    ALTER TABLE tenants 
    ADD COLUMN IF NOT EXISTS whatsapp_config JSONB DEFAULT NULL,
    ADD COLUMN IF NOT EXISTS instagram_config JSONB DEFAULT NULL;
    
    -- Create indexes for faster lookups
    CREATE INDEX IF NOT EXISTS idx_tenants_whatsapp_config ON tenants USING GIN (whatsapp_config);
    CREATE INDEX IF NOT EXISTS idx_tenants_instagram_config ON tenants USING GIN (instagram_config);
    
    -- Comments
    COMMENT ON COLUMN tenants.whatsapp_config IS 'WhatsApp Business API configuration: { access_token, phone_number_id, verify_token }';
    COMMENT ON COLUMN tenants.instagram_config IS 'Instagram Direct API configuration: { access_token, page_id, verify_token }';
    """
    
    print("🔄 Applying Meta Channels migration...")
    
    async with async_engine.begin() as conn:
        await conn.execute(text(migration_sql))
    
    print("✅ Migration applied successfully!")
    print("   - Added whatsapp_config column (JSONB)")
    print("   - Added instagram_config column (JSONB)")
    print("   - Created GIN indexes")


if __name__ == "__main__":
    asyncio.run(apply_migration())