Skip to content

Commit 70f1bee

Browse files
committed
feat: add migration creation script and remove deprecated Chatwoot integration
- Introduced a new script for generating database migrations. - Removed the Chatwoot integration and related files across various services and controllers. - Updated package.json to include the new migration script command. - Cleaned up unused schemas and DTOs related to Chatwoot and other integrations.
1 parent 6efa879 commit 70f1bee

File tree

82 files changed

+1620
-18912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1620
-18912
lines changed

createMigration.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const dotenv = require('dotenv');
2+
const { execSync } = require('child_process');
3+
const { existsSync } = require('fs');
4+
5+
dotenv.config();
6+
7+
const { DATABASE_PROVIDER } = process.env;
8+
const databaseProviderDefault = DATABASE_PROVIDER ?? 'postgresql';
9+
const migrationName = process.argv[2];
10+
11+
if (!migrationName) {
12+
console.error('Error: Migration name is required');
13+
console.log('Usage: node createMigration.js <migration_name>');
14+
process.exit(1);
15+
}
16+
17+
if (!DATABASE_PROVIDER) {
18+
console.warn(`DATABASE_PROVIDER is not set in the .env file, using default: ${databaseProviderDefault}`);
19+
}
20+
21+
function getMigrationsFolder(provider) {
22+
switch (provider) {
23+
case 'psql_bouncer':
24+
return 'postgresql-migrations';
25+
default:
26+
return `${provider}-migrations`;
27+
}
28+
}
29+
30+
const migrationsFolder = getMigrationsFolder(databaseProviderDefault);
31+
const schemaFile = `./prisma/${databaseProviderDefault}-schema.prisma`;
32+
33+
console.log(`Creating migration: ${migrationName}`);
34+
console.log(`Database provider: ${databaseProviderDefault}`);
35+
console.log(`Migrations folder: ${migrationsFolder}`);
36+
37+
try {
38+
// Copiar migrations existentes
39+
execSync(`rm -rf ./prisma/migrations`, { stdio: 'inherit' });
40+
execSync(`cp -r ./prisma/${migrationsFolder} ./prisma/migrations`, { stdio: 'inherit' });
41+
42+
// Verificar status das migrações primeiro
43+
console.log('\n📋 Checking migration status...');
44+
try {
45+
const statusOutput = execSync(`npx prisma migrate status --schema ${schemaFile}`, {
46+
encoding: 'utf8',
47+
stdio: 'pipe'
48+
});
49+
console.log(statusOutput);
50+
} catch (statusError) {
51+
const errorOutput = statusError.stdout?.toString() || statusError.stderr?.toString() || '';
52+
if (errorOutput.includes('was modified after it was applied')) {
53+
console.log('\n⚠️ Detected modified migration. Attempting to resolve...');
54+
console.log('💡 If this fails, you may need to run: npx prisma migrate reset --schema ' + schemaFile);
55+
console.log(' (WARNING: This will drop all data in the database)\n');
56+
}
57+
}
58+
59+
// Criar nova migração
60+
console.log(`\n🚀 Creating migration: ${migrationName}`);
61+
execSync(`npx prisma migrate dev --name ${migrationName} --schema ${schemaFile}`, { stdio: 'inherit' });
62+
63+
// Copiar nova migração de volta
64+
execSync(`cp -r ./prisma/migrations/* ./prisma/${migrationsFolder}`, { stdio: 'inherit' });
65+
66+
console.log(`\n✅ Migration "${migrationName}" created successfully!`);
67+
} catch (error) {
68+
const errorOutput = error.stdout?.toString() || error.stderr?.toString() || error.message;
69+
if (errorOutput.includes('was modified after it was applied')) {
70+
console.error(`\n❌ Migration conflict detected!`);
71+
console.error(`\n📝 To resolve this, you have two options:\n`);
72+
console.error(` 1. Reset the database (WARNING: Drops all data):`);
73+
console.error(` npx prisma migrate reset --schema ${schemaFile}\n`);
74+
console.error(` 2. Mark the migration as resolved (if you know what you're doing):`);
75+
console.error(` npx prisma migrate resolve --applied 20250918182355_add_kafka_integration --schema ${schemaFile}\n`);
76+
} else {
77+
console.error(`\n❌ Error creating migration: ${errorOutput}`);
78+
}
79+
process.exit(1);
80+
}
81+

evolution-manager-v2

Submodule evolution-manager-v2 deleted from f054b9b

0 commit comments

Comments
 (0)