Repository: typeorm/typeorm
File: src/migration/MigrationExecutor.ts (TypeScript)

Code before:
    /**
     * Tries to execute a single migration given.
     */
    public async executeMigration(migration: Migration): Promise<Migration> {
        return this.withQueryRunner(async (queryRunner) => {
            await this.createMigrationsTableIfNotExist(queryRunner)

            // create typeorm_metadata table if it's not created yet
            const schemaBuilder = this.connection.driver.createSchemaBuilder()
            if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {
                await schemaBuilder.createMetadataTableIfNecessary(queryRunner)
            }

            await queryRunner.beforeMigration()
            await (migration.instance as any).up(queryRunner)
            await queryRunner.afterMigration()
            await this.insertExecutedMigration(queryRunner, migration)

            return migration
        })
    }

    /**
     * @returns An array of all executed migrations
     */
    public async getExecutedMigrations(): Promise<Migration[]> {
        return this.withQueryRunner(async (queryRunner) => {
            // There is no need to check if migrations table exists for MongoDB,
            // as it's handled in loadExecutedMigrations
            if (this.connection.driver.options.type !== "mongodb") {
                const exist = await queryRunner.hasTable(this.migrationsTable)

                if (!exist) return []
            }

            return await this.loadExecutedMigrations(queryRunner)
        })
    }

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

        if (executedMigrations.length === 0) return allMigrations

        return allMigrations.filter(
            (migration) =>
                !executedMigrations.find(

Review comment (refactor):
Imo we shouldn't remove this as it's a breaking change, perhaps worth deprecating and removing in v1, wdyt?

Code after:
    /**
     * Tries to execute a single migration given.
     */
    public async executeMigration(migration: Migration): Promise<Migration> {
        return this.withQueryRunner(async (queryRunner) => {
            await this.createMigrationsTableIfNotExist(queryRunner)

            // create typeorm_metadata table if it's not created yet
            const schemaBuilder = this.connection.driver.createSchemaBuilder()
            if (InstanceChecker.isRdbmsSchemaBuilder(schemaBuilder)) {
                await schemaBuilder.createMetadataTableIfNecessary(queryRunner)
            }

            await queryRunner.beforeMigration()
            await (migration.instance as any).up(queryRunner)
            await queryRunner.afterMigration()
            await this.insertExecutedMigration(queryRunner, migration)

            return migration
        })
    }

    /**
     * Returns an array of all migrations.
     *
     * @deprecated use getMigrations instead
     */
    public async getAllMigrations(): Promise<Migration[]> {
        return Promise.resolve(this.getMigrations())
    }

    /**
     * @returns An array of all executed migrations
     */
    public async getExecutedMigrations(): Promise<Migration[]> {
        return this.withQueryRunner(async (queryRunner) => {
            // There is no need to check if migrations table exists for MongoDB,
            // as it's handled in loadExecutedMigrations
            if (this.connection.driver.options.type !== "mongodb") {
                const exist = await queryRunner.hasTable(this.migrationsTable)

                if (!exist) return []
            }

            return await this.loadExecutedMigrations(queryRunner)
        })
    }

    /**
     * Returns an array of all pending migrations.
     */