Skip to content

Commit

Permalink
add support for submodule migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Иванов Сергей committed Jun 11, 2024
1 parent a4001b4 commit 055c83a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@steroidsjs/nest",
"version": "2.0.2",
"version": "2.0.3",
"scripts": {
"script": "nps",
"watch": "nps watch",
Expand Down
15 changes: 14 additions & 1 deletion src/infrastructure/applications/console/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ import {CommandModule} from 'nestjs-command';

const isMigrateCommand = !!(process.argv || []).find(arg => /^migrate/.exec(arg));

// search migrations in modules and subModules
const collectMigrations = (modulePath: string, migrations: string[] = []) => {
fs.readdirSync(modulePath).forEach(moduleName => {
migrations.push(path.join(modulePath, `${moduleName}/infrastructure/migrations/*{.ts,.js}`));

const childModulesPath = path.join(modulePath, `${moduleName}/modules`);
if (fs.existsSync(childModulesPath)) {
collectMigrations(childModulesPath, migrations);
}
})
return migrations;
}

export default {
...baseConfig,
config: () => {
Expand All @@ -27,7 +40,7 @@ export default {
database: {
...config.database,
migrations: isMigrateCommand
? fs.readdirSync(migrationsRootDir).map(name => path.join(migrationsRootDir, `${name}/infrastructure/migrations/*{.ts,.js}`))
? collectMigrations(migrationsRootDir)
: [], // Do not include migrations on web and other cli commands
migrationsTableName: 'migrations',
} as PostgresConnectionOptions
Expand Down

0 comments on commit 055c83a

Please sign in to comment.