File size: 1,104 Bytes
e286845
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { PrismaClient } from '@prisma/client';
import * as dotenv from 'dotenv';
import * as path from 'path';

dotenv.config({ path: path.join(__dirname, '../../.env') });

const prisma = new PrismaClient();

async function main() {
    console.log('🚀 Starting modular flags migration...');

    const orgs = await prisma.organization.findMany();
    console.log(`Found ${orgs.length} organizations to update.`);

    for (const org of orgs) {
        const isCrmActive = org.useCase === 'CRM_WHATSAPP';
        const isEdTechActive = org.useCase === 'EDUCATION';

        await prisma.organization.update({
            where: { id: org.id },
            data: {
                isCrmActive,
                isEdTechActive
            }
        });
        console.log(`✅ Updated Org: ${org.name} (CRM: ${isCrmActive}, EdTech: ${isEdTechActive})`);
    }

    console.log('✨ Migration completed successfully!');
}

main()
    .catch((e) => {
        console.error('❌ Migration failed:', e);
        process.exit(1);
    })
    .finally(async () => {
        await prisma.$disconnect();
    });