Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MigrationExecutor.getPendingMigrations() is not working properly #5425

Closed
davilopez90 opened this issue Jan 27, 2020 · 4 comments
Closed

MigrationExecutor.getPendingMigrations() is not working properly #5425

davilopez90 opened this issue Jan 27, 2020 · 4 comments

Comments

@davilopez90
Copy link

davilopez90 commented Jan 27, 2020

Issue type:

[ ] question
[X] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[X] cordova
[X] mongodb
[X] mssql
[X] mysql / mariadb
[X] oracle
[X] postgres
[X] cockroachdb
[X] sqlite
[X] sqljs
[X] react-native
[X] expo

TypeORM version:

[X] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I've detected a bug in MigrationExecutor.getPendingMigrations()
It's not filtering properly. In facto, it's not filtering at all, it's just returning allMigrations:

    /**
     * Returns an array of all pending migrations.
     */
    public async getPendingMigrations(): Promise<Migration[]> {
        const allMigrations = await this.getAllMigrations();
        const executedMigrations = await this.getExecutedMigrations();

        return allMigrations.filter(migration =>
            executedMigrations.find(
                executedMigration =>
                    executedMigration.name === migration.name
            )
        );
    }

This method should return actually pendingMigrations, I mean, the migrations contained in allMigrations but not in executedMigrations.
Solutions/proposals to solve this bug:

  • Add a ! before executedMigrations.find
    public async getPendingMigrations(): Promise<Migration[]> {
        const allMigrations = await this.getAllMigrations();
        const executedMigrations = await this.getExecutedMigrations();

        return allMigrations.filter(migration =>
            !executedMigrations.find(
                executedMigration =>
                    executedMigration.name === migration.name
            )
        );
    }
@captainjapeng
Copy link

In my case getPendingMigrations is returning all executed migrations similar to getExecutedMigrations.

Version: "typeorm": "^0.2.24"

@MartinodF
Copy link

I agree with @captainjapeng: instead of filtering out executedMigrations, thus returning only the pending ones, it's filtering only executedMigrations. Still happening in 0.2.25, and the proposed fix (adding ! before the filter call) is correct.

@bk3c
Copy link

bk3c commented Sep 1, 2020

Looks like this was fixed and merged in #6372; just waiting on a release.

@imnotjames
Copy link
Contributor

The fix was released so I'm closing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment