Skip to content

Commit

Permalink
FIX: #9 missing migration files
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael O'Brien committed Aug 6, 2024
1 parent 083b9ca commit e8a6089
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,33 @@ export class Migrate {
}

} else if (action == 'up' || action === 1 || action == 'repeat' || action === 2) {
let found
for (let v of versions) {
if (Semver.compare(v, currentVersion) <= 0) {
continue
}
if (Semver.compare(v, version) > 0) {
break
}
found = Semver.compare(v, version) == 0
migration = await this.invokeMigration('up', v, options)
}
if (!found) {
throw new Error('Cannot find target migration ${version}')
}

} else if (action == 'down' || action === -1) {
let pastMigrations = await this.getPastMigrations()

let found
for (let v of versions.reverse()) {
if (Semver.compare(v, currentVersion) > 0) {
continue
}
if (Semver.compare(v, version) < 0) {
break
}
found = Semver.compare(v, version) == 0
migration = await this.invokeMigration('down', v, options)

if (!options.dry) {
Expand All @@ -108,6 +116,9 @@ export class Migrate {
await db.saveSchema(migration.schema)
}
}
if (!found) {
throw new Error('Cannot find target migration ${version}')
}
} else {
// Named migration
migration = await this.invokeMigration('up', action, options)
Expand Down

0 comments on commit e8a6089

Please sign in to comment.