michaldudek / nestjs-typeorm-commands

TypeORM CLI commands for NestJS
MIT License
12 stars 3 forks source link

`npm run migration:run` not executing migrations #1

Open mohammadxali opened 1 year ago

mohammadxali commented 1 year ago

app.module.ts

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CoffeesModule } from './coffees/coffees.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { NestTypeOrmCommandsModule } from 'nestjs-typeorm-commands';

@Module({
    imports: [
        CoffeesModule,
        TypeOrmModule.forRoot({
            type: 'postgres',
            host: 'localhost',
            port: 5432,
            username: 'postgres',
            password: 'pass123',
            database: 'postgres',
            autoLoadEntities: true,
        }),
        NestTypeOrmCommandsModule.forRoot({
            migrationsDir: 'src/migrations',
        }),
    ],
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule {}

After running npm run migration:run I get the following output, telling me that no migrations are pending:

$ npm run migration:run

> testing-project@0.0.1 migration:run
> ts-node -r tsconfig-paths/register src/cli.ts typeorm migration:run

query: SELECT version();
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = 'public' AND "table_name" = 'migrations'
query: SELECT * FROM "migrations" "migrations" ORDER BY "id" DESC
No migrations are pending

However, I do see migrations exist in dist/migration folder in Nest.

I tried adding migrations: ['dist/migrations/*.js'], to TypeOrmModule.forRoot as well but it didn't work as well.

Steps to reproduce:

  1. Clone the repo: https://github.com/MohammadxAli/iluvecoffee-nestjs-test
  2. Run pnpm install to install deps & then run docker-compose up -d to run postgres db
  3. Open src/coffees/entities/coffee.entity.ts file and append a new description column like so:
    @Column({ nullable: true })
    description: string;
  4. Run npm run migration:generate SchemaSync to generate migration
  5. Run npm run build to build the app
  6. Run npm run migration:run and then you will see it doesn't run the new migration
VivaThapelo commented 1 year ago

+1