MigrationConfig

public struct MigrationConfig : Service

Configures Migrations for your Fluent databases.

var migrations = MigrationConfig()
migrations.add(model: User.self, database: .psql)
migrations.add(migration: AddAgeProperty.self, database: .psql)
services.register(migrations)

You can configure both Migrations and Model & Migrations. When you configure a Model & Migration, the defaultDatabase property will also be set.

  • Create a new, empty MigrationConfig.

    Declaration

    Swift

    public init()
  • Adds a Model & Migration to the MigrationConfig.

    Warning

    Use add(model:) if the migration you are adding is also a Model.

    migrationConfig.add(model: User.self, database: .sqlite)

    This method sets the model’s defaultDatabase property.

    Declaration

    Swift

    public mutating func add<Model>(model: Model.Type, database: DatabaseIdentifier<Model.Database>)
        where Model: Fluent.Migration & Fluent.Model

    Parameters

    model

    Model & Migration type to add.

  • Adds a Migration to the MigrationConfig.

    Warning

    Use add(model:) if the migration you are adding is also a Model.

    migrationConfig.add(migration: CleanupUsers.self, database: .sqlite)

    Declaration

    Swift

    public mutating func add<Migration>(migration: Migration.Type, database: DatabaseIdentifier<Migration.Database>)
        where Migration: Fluent.Migration

    Parameters

    migration

    Migration type to add.

    database

    Database identifier for the database this should run on.

  • Prepares a single batch of migrations.

    Declaration

    Swift

    public func prepare(on container: Container) -> Future<Void>

    Parameters

    container

    Container to use for fetching connections.

    Return Value

    A future that will complete when the task is finished.

  • Reverts a single batch of prepared migrations.

    Declaration

    Swift

    public func revert(on container: Container) -> Future<Void>

    Parameters

    container

    Container to use for fetching connections.

    Return Value

    A future that will complete when the task is finished.

  • Reverts all prepared migrations.

    Declaration

    Swift

    public func revertAll(on container: Container) -> Future<Void>

    Parameters

    container

    Container to use for fetching connections.

    Return Value

    A future that will complete when the task is finished.