diff --git a/api/package.json b/api/package.json index 98b6334b..43a78026 100644 --- a/api/package.json +++ b/api/package.json @@ -39,7 +39,7 @@ "typecheck": "tsc --noEmit", "reset": "npm install && npm run containers:restart", "reset:hard": "npm clean-install && npm run containers:rebuild", - "cli": "DEBUG=ts-node* ts-node --files --log-error --compiler-options '{\"diagnostics\": true}' src/cli.ts" + "cli": "HEXABOT_CLI=1 ts-node --files --log-error --compiler-options '{\"diagnostics\": true}' src/cli.ts" }, "lint-staged": { "*.{js,ts}": "eslint --fix -c \".eslintrc-staged.js\"" diff --git a/api/src/config/index.ts b/api/src/config/index.ts index 1869bc81..74033d61 100644 --- a/api/src/config/index.ts +++ b/api/src/config/index.ts @@ -149,9 +149,11 @@ export const config: Config = { process.env.MONGO_URI || 'mongodb://dev_only:dev_only@localhost:27017/', dbName: process.env.MONGO_DB || 'hexabot', autoMigrate: - process.env.MONGO_AUTO_MIGRATE === 'true' - ? Boolean(process.env.MONGO_AUTO_MIGRATE) - : false, + // Either auto-migration is explicitly enabled and the node is primary (cluster case) + (process.env.MONGO_AUTO_MIGRATE === 'true' && + (process.env.API_IS_PRIMARY_NODE || 'true') === 'true') || + // Otherwise, run only in dev mode + !(process.env.NODE_ENV || 'development').toLowerCase().includes('prod'), }, env: process.env.NODE_ENV || 'development', authentication: { diff --git a/api/src/migration/migration.service.ts b/api/src/migration/migration.service.ts index ae87c58d..c3669d59 100644 --- a/api/src/migration/migration.service.ts +++ b/api/src/migration/migration.service.ts @@ -52,8 +52,8 @@ export class MigrationService implements OnApplicationBootstrap { } this.logger.log('Mongoose connection established'); - const isProduction = config.env.toLowerCase().includes('prod'); - if (!isProduction && config.mongo.autoMigrate) { + const isCLI = Boolean(process.env.HEXABOT_CLI); + if (!isCLI && config.mongo.autoMigrate) { this.logger.log('Executing migrations ...'); const { value: version = '2.1.9' } = await this.metadataService.getMetadata('db-version'); diff --git a/api/src/migration/migrations/1735840203378-v-2-2-0.migration.ts b/api/src/migration/migrations/1735840203378-v-2-2-0.migration.ts deleted file mode 100644 index 7f0e40fb..00000000 --- a/api/src/migration/migrations/1735840203378-v-2-2-0.migration.ts +++ /dev/null @@ -1,10 +0,0 @@ -import mongoose from 'mongoose'; - -module.exports = { - async up() { - // Migration logic - }, - async down() { - // Rollback logic - }, -}; \ No newline at end of file diff --git a/docker/.env.example b/docker/.env.example index e14ad335..31accd7c 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -1,11 +1,12 @@ # API & Common -NODE_ENV=dev +NODE_ENV=development APP_DOMAIN=localhost SSL_EMAIL=hello@hexabot.ai API_PORT=4000 APP_FRONTEND_PORT=8080 APP_SCRIPT_COMPODOC_PORT=9003 API_ORIGIN=http://${APP_DOMAIN}:${API_PORT} +API_IS_PRIMARY_NODE=true FRONTEND_BASE_URL=http://${APP_DOMAIN}:${APP_FRONTEND_PORT} FRONTEND_ORIGIN=${FRONTEND_BASE_URL},http://${APP_DOMAIN}:8081,http://${APP_DOMAIN}:5173,http://${APP_DOMAIN},https://${APP_DOMAIN} JWT_SECRET=dev_only