Spaces:
Running

microfunnel-api / backend /apply_meta_migration.py
MicroFunnel
Production-ready: Refactored codebase with Railway + Vercel config
cd61bf7
Raw History Blame Contribute Delete
1.49 kB
"""
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())