Skip to content

Commit

Permalink
Merge pull request #3 from SwifQL/replace-name-with-migrationName
Browse files Browse the repository at this point in the history
AnyMigration: replace `name` with `migrationName`
  • Loading branch information
MihaelIsaev committed May 6, 2020
2 parents 8aeab0d + 2c3f180 commit fc15c7b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Sources/Bridges/DatabaseMigrations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ public class BridgeDatabaseMigrations<B: Bridgeable>: Migrator {
return conn.query(raw: query, decoding: Migrations.self).flatMap { completedMigrations in
let batch = completedMigrations.map { $0.batch }.max() ?? 0
var migrations = self.migrations
migrations.removeAll { m in completedMigrations.contains { $0.name == m.name } }
migrations.removeAll { m in completedMigrations.contains { $0.name == m.migrationName } }
return migrations.map { migration in
{
migration.prepare(on: conn).flatMap {
SwifQL
.insertInto(self.m.table, fields: self.m.$name, self.m.$batch)
.values
.values(migration.name, batch + 1)
.values(migration.migrationName, batch + 1)
.execute(on: conn)
}
}
Expand All @@ -130,13 +130,13 @@ public class BridgeDatabaseMigrations<B: Bridgeable>: Migrator {
else { return conn.eventLoop.future(false) }
let migrationsToRevert = completedMigrations.filter { $0.batch == lastBatch }
var migrations = self.migrations
migrations.removeAll { m in migrationsToRevert.contains { $0.name != m.name } }
migrations.removeAll { m in migrationsToRevert.contains { $0.name != m.migrationName } }
return migrations.map { migration in
{
migration.revert(on: conn).flatMap {
SwifQL
.delete(from: self.m.table)
.where(self.m.$name == migration.name)
.where(self.m.$name == migration.migrationName)
.execute(on: conn)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Bridges/Protocols/AnyMigration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import NIO

public protocol AnyMigration {
static var name: String { get }
static var migrationName: String { get }

static func prepare(on conn: BridgeConnection) -> EventLoopFuture<Void>
static func revert(on conn: BridgeConnection) -> EventLoopFuture<Void>
}

extension AnyMigration {
public static var name: String { String(describing: Self.self) }
public static var migrationName: String { String(describing: Self.self) }
}

0 comments on commit fc15c7b

Please sign in to comment.