0.2.0 • Published 2 months ago

@jchpro/nest-mongoose v0.2.0

Weekly downloads
-
License
LGPL-3.0-only
Repository
github
Last release
2 months ago

Nest Mongoose

Utilities for Nest.js apps using Mongoose. Includes Migrate CLI for database migrations.

Description

Currently only Migrate CLI is implemented, and in its most basic capability. More stuff probably coming soon.

Installation

npm i @jchpro/nest-mongoose

I'm not a fan of installing too many CLIs globally, so in this document I'll be showing example commands run using npx, assuming that the package is installed locally in your project.

Migrate CLI usage

Setup

npx mongo-migrate setup <applicationProject> <options...> 

This will add mongoMigrate section to the package.json, based on your input options. Please run the command with --help to get more info.

Generate

npx mongo-migrate generate "Some descriptive name of the migration" 

This will generate the migration file in the project (--project option or uses the default one) and regenerate the "collector" file.

Running migrations on app startup

// app.module.ts

// Default name of the "collector" file.
import migrations from './app.migrations';

@Module({
  imports: [
    // Import the Migration module with migrations
    MongoMigrateModule.withMigrations(migrations),
  ]
})
export class AppModule { }
// main.ts

import { Migrator } from '@jchpro/nest-mongoose';

async function bootstrap() {
  // Prepare your app here
  const app = await NestFactory.create(AppModule);
  
  // Run database migrations `up`
  await new Migrator(app).up();
}
0.2.0

2 months ago

0.1.1

2 months ago

0.1.0

2 months ago