Skip to content

Commit

Permalink
fix: only create migrations folder if migrationsList is not used (#941)
Browse files Browse the repository at this point in the history
Related: #907
  • Loading branch information
thomaschaaf committed Oct 21, 2020
1 parent 82f7f0a commit 1e5c5e8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/migrations/src/Migrator.ts
Expand Up @@ -26,7 +26,7 @@ export class Migrator {
customResolver: (file: string) => this.resolve(file),
};

if (this.options.migrationsList?.length) {
if (this.options.migrationsList) {
const list = this.options.migrationsList.map(migration => this.initialize(migration.class as Constructor<Migration>, migration.name));
migrations = migrationsList(list as any[]);
}
Expand All @@ -39,7 +39,7 @@ export class Migrator {
}

async createMigration(path?: string, blank = false, initial = false): Promise<MigrationResult> {
await ensureDir(Utils.normalizePath(this.options.path!));
await this.ensureMigrationsDirExists();

if (initial) {
await this.validateInitialMigration();
Expand Down Expand Up @@ -74,13 +74,13 @@ export class Migrator {
}

async getExecutedMigrations(): Promise<MigrationRow[]> {
await ensureDir(Utils.normalizePath(this.options.path!));
await this.ensureMigrationsDirExists();
await this.storage.ensureTable();
return this.storage.getExecutedMigrations();
}

async getPendingMigrations(): Promise<UmzugMigration[]> {
await ensureDir(Utils.normalizePath(this.options.path!));
await this.ensureMigrationsDirExists();
await this.storage.ensureTable();
return this.umzug.pending();
}
Expand Down Expand Up @@ -165,7 +165,7 @@ export class Migrator {
}

private async runMigrations(method: 'up' | 'down', options?: string | string[] | MigrateOptions) {
await ensureDir(Utils.normalizePath(this.options.path!));
await this.ensureMigrationsDirExists();
await this.storage.ensureTable();

if (!this.options.transactional || !this.options.allOrNothing) {
Expand All @@ -189,4 +189,10 @@ export class Migrator {
return ret;
}

private async ensureMigrationsDirExists() {
if (!this.options.migrationsList) {
await ensureDir(Utils.normalizePath(this.options.path!));
}
}

}

0 comments on commit 1e5c5e8

Please sign in to comment.