Wiki

Clone wiki

NuGet.PowerShell / FluentMigrator.PowerShell

FluentMigrator.PowerShell

This packages exposes functions to migrate a FluentMigrator database up or down.

Dependencies

This package requires FluentMigrator to be installed in at least one project.

If your computer is 64 bits or if you are running .NET 3.5, you also need to have FluentMigrator.Tools installed in at least one project.

NuGet package

Available here

Usage

Install via NuGet (see above) inside the Package Manager Console in Visual Studio.

Once installed, the commands should be available below. Start using them as you please.

Documentation

This documentation is generated from the comments inside the module itself. If something is missing, do not hesitate to submit a pull request to the main code and update the documentation with the appropriate command (GenerateDocumentation.ps1!).

Cmdlets

This is a list of Cmdlets that are added when importing this module.

Get-Assemblies

NAME
    Get-Assemblies

SYNOPSIS
    Loads assemblies from a file as JSON. Assemblies can then be passed to any other Cmdlet from this module and it will iterate over each assembly while executing the command.

    Any non-mandatory parameter in the JSON can be overriden by passing it directly to the Cmdlet afterwards.


SYNTAX
    Get-Assemblies [-FileName] <String> [<CommonParameters>]


DESCRIPTION


PARAMETERS
    -FileName <String>
        The path to the JSON file containing the assemblies.

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see 
        about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

    -------------------------- EXAMPLE 1 --------------------------

    PS C:\>Get-Assemblies

    The assembly file is an array with each object containing at least the following properties: Assembly, Provider, ConnectionString (or ConnectionStringName and ConnectionStringConfigurationPath).




REMARKS
    To see the examples, type: "get-help Get-Assemblies -examples".
    For more information, type: "get-help Get-Assemblies -detailed".
    For technical information, type: "get-help Get-Assemblies -full".

Get-DatabaseMigration

NAME
    Get-DatabaseMigration

SYNOPSIS
    Gets a list of migrations for the specified database.


SYNTAX
    Get-DatabaseMigration [[-Assembly] <String>] [[-Assemblies] <Array>] [[-Provider] {SqlServer2000 | SqlServer2005 | SqlServer2008 | SqlServer2012 | SqlServerce | SqlServer | MySql | PostGres | Oracle | SQLite | Jet}] [[-ConnectionString] <String>] 
    [[-ConnectionStringName] <String>] [[-ConnectionStringConfigurationPath] <String>] [[-Namespace] <String>] [-Nested] [-TransactionPerSession] [[-Timeout] <Int32>] [[-WorkingDirectory] <String>] [[-Tag] <String>] [[-Context] <String>] [-WhatIf] 
    [-DoNotKillExistingConnections] [<CommonParameters>]


DESCRIPTION


PARAMETERS
    -Assembly <String>
        The path to the DLL that contains the migrations

    -Assemblies <Array>
        A list of assemblies to run for that command. Get them using Get-Assemblies Cmdlet.

    -Provider
        The provider for the Database (See the DatabaseProvider enum for a list). Default is SqlServer2012

    -ConnectionString <String>
        The connection string to the database to read migrations for.

    -ConnectionStringName <String>
        The name of the connection string to the database to read migrations for. Requires passing "ConnectionStringConfigurationPath" as well.

    -ConnectionStringConfigurationPath <String>
        The path to a configuration file to use for reading connection strings.

    -Namespace <String>
        A specific namespace to look for migrations.

    -Nested [<SwitchParameter>]
        Whether migrations in nested namespaces should be included. Used in conjunction with the Namespace parameter.

    -TransactionPerSession [<SwitchParameter>]
        The default transaction is one transaction per migration so the default for this switch is false. Run migrations in one transaction per session (task) instead.

    -Timeout <Int32>
        Overrides the default SqlCommand timeout of 30 seconds.

    -WorkingDirectory <String>
        The directory to load SQL scripts specified by migrations from.

    -Tag <String>
        Filters migrations to be run based on tags.

    -Context <String>
        A string argument that can be used in a migration.

    -WhatIf [<SwitchParameter>]
        Only outputs what would happen.

    -DoNotKillExistingConnections [<SwitchParameter>]
        Do not kill existing connections to the database being migrated. This could cause a migration to fail

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see 
        about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

    -------------------------- EXAMPLE 1 --------------------------

    PS C:\>Get-DatabaseMigration -Assembly .\Core.NH\bin\Debug\Core.NH.dll -Provider SqlServer2012 -ConnectionStringName "Core" -ConnectionStringConfigurationPath .\.config\defaultapp.config






REMARKS
    To see the examples, type: "get-help Get-DatabaseMigration -examples".
    For more information, type: "get-help Get-DatabaseMigration -detailed".
    For technical information, type: "get-help Get-DatabaseMigration -full".

Rollback-Database

NAME
    Rollback-Database

SYNOPSIS
    Roll back the database to a previous version.


SYNTAX
    Rollback-Database [[-Assembly] <String>] [[-Assemblies] <Array>] [[-Provider] {SqlServer2000 | SqlServer2005 | SqlServer2008 | SqlServer2012 | SqlServerce | SqlServer | MySql | PostGres | Oracle | SQLite | Jet}] [[-ConnectionString] <String>] 
    [[-ConnectionStringName] <String>] [[-ConnectionStringConfigurationPath] <String>] [-All] [[-Version] <String>] [[-Namespace] <String>] [-Nested] [-TransactionPerSession] [-Preview] [[-Timeout] <Int32>] [[-WorkingDirectory] <String>] [[-Tag] <String>] 
    [[-Context] <String>] [-Output] [[-OutputFileName] <String>] [[-Steps] <Int32>] [-WhatIf] [-DoNotKillExistingConnections] [<CommonParameters>]


DESCRIPTION


PARAMETERS
    -Assembly <String>
        The path to the DLL that contains the migrations

    -Assemblies <Array>
        A list of assemblies to run for that command. Get them using Get-Assemblies Cmdlet.

    -Provider
        The provider for the Database (See the DatabaseProvider enum for a list). Default is SqlServer2012

    -ConnectionString <String>
        The connection string to the database to read migrations for.

    -ConnectionStringName <String>
        The name of the connection string to the database to read migrations for. Requires passing "ConnectionStringConfigurationPath" as well.

    -ConnectionStringConfigurationPath <String>
        The path to a configuration file to use for reading connection strings.

    -All [<SwitchParameter>]
        If specified, rolls back all migrations.

    -Version <String>

    -Namespace <String>
        A specific namespace to look for migrations.

    -Nested [<SwitchParameter>]
        Whether migrations in nested namespaces should be included. Used in conjunction with the Namespace parameter.

    -TransactionPerSession [<SwitchParameter>]
        The default transaction is one transaction per migration so the default for this switch is false. Run migrations in one transaction per session (task) instead.

    -Preview [<SwitchParameter>]

    -Timeout <Int32>
        Overrides the default SqlCommand timeout of 30 seconds.

    -WorkingDirectory <String>
        The directory to load SQL scripts specified by migrations from.

    -Tag <String>
        Filters migrations to be run based on tags.

    -Context <String>
        A string argument that can be used in a migration.

    -Output [<SwitchParameter>]
        Whether to output to an SQL file. Default SQL file is {AssemblyName}.sql

    -OutputFileName <String>
        FileName for SQL file if -Output is specified.

    -Steps <Int32>
        Number of versions to rollback. Default is 1.

    -WhatIf [<SwitchParameter>]
        Only outputs what would happen.

    -DoNotKillExistingConnections [<SwitchParameter>]
        Do not kill existing connections to the database being migrated. This could cause a migration to fail

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see 
        about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

    -------------------------- EXAMPLE 1 --------------------------

    PS C:\>Rollback-Database -Assembly .\Core.NH\bin\Debug\Core.NH.dll -Provider SqlServer2012 -ConnectionStringName "Core" -ConnectionStringConfigurationPath .\.config\defaultapp.config -Steps 2






REMARKS
    To see the examples, type: "get-help Rollback-Database -examples".
    For more information, type: "get-help Rollback-Database -detailed".
    For technical information, type: "get-help Rollback-Database -full".

Update-Database

NAME
    Update-Database

SYNOPSIS
    Updates the database to the latest version.


SYNTAX
    Update-Database [[-Assembly] <String>] [[-Assemblies] <Array>] [[-Provider] {SqlServer2000 | SqlServer2005 | SqlServer2008 | SqlServer2012 | SqlServerce | SqlServer | MySql | PostGres | Oracle | SQLite | Jet}] [[-ConnectionString] <String>] 
    [[-ConnectionStringName] <String>] [[-ConnectionStringConfigurationPath] <String>] [[-Version] <String>] [[-Namespace] <String>] [-DeleteBeforeMigrating] [-Nested] [-TransactionPerSession] [-Preview] [[-Timeout] <Int32>] [[-WorkingDirectory] <String>] 
    [[-Tag] <String>] [[-Context] <String>] [[-Profile] <String>] [-Output] [[-OutputFileName] <String>] [-WhatIf] [-DoNotKillExistingConnections] [<CommonParameters>]


DESCRIPTION


PARAMETERS
    -Assembly <String>
        The path to the DLL that contains the migrations

    -Assemblies <Array>
        A list of assemblies to run for that command. Get them using Get-Assemblies Cmdlet.

    -Provider
        The provider for the Database (See the DatabaseProvider enum for a list). Default is SqlServer2012

    -ConnectionString <String>
        The connection string to the database to read migrations for.

    -ConnectionStringName <String>
        The name of the connection string to the database to read migrations for. Requires passing "ConnectionStringConfigurationPath" as well.

    -ConnectionStringConfigurationPath <String>
        The path to a configuration file to use for reading connection strings.

    -Version <String>

    -Namespace <String>
        A specific namespace to look for migrations.

    -DeleteBeforeMigrating [<SwitchParameter>]
        If specified, the database will be deleted before executing the migration. Used for starting anew.

    -Nested [<SwitchParameter>]
        Whether migrations in nested namespaces should be included. Used in conjunction with the Namespace parameter.

    -TransactionPerSession [<SwitchParameter>]
        The default transaction is one transaction per migration so the default for this switch is false. Run migrations in one transaction per session (task) instead.

    -Preview [<SwitchParameter>]

    -Timeout <Int32>
        Overrides the default SqlCommand timeout of 30 seconds.

    -WorkingDirectory <String>
        The directory to load SQL scripts specified by migrations from.

    -Tag <String>
        Filters migrations to be run based on tags.

    -Context <String>
        A string argument that can be used in a migration.

    -Profile <String>
        A profile to run after migrations are done.

    -Output [<SwitchParameter>]
        Whether to output to an SQL file. Default SQL file is {AssemblyName}.sql

    -OutputFileName <String>
        FileName for SQL file if -Output is specified.

    -WhatIf [<SwitchParameter>]
        Only outputs what would happen.

    -DoNotKillExistingConnections [<SwitchParameter>]
        Do not kill existing connections to the database being migrated. This could cause a migration to fail

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see 
        about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

    -------------------------- EXAMPLE 1 --------------------------

    PS C:\>Update-Database -Assembly .\Core.NH\bin\Debug\Core.NH.dll -Provider SqlServer2012 -ConnectionStringName "Core" -ConnectionStringConfigurationPath .\.config\defaultapp.config -DeleteBeforeMigrating






REMARKS
    To see the examples, type: "get-help Update-Database -examples".
    For more information, type: "get-help Update-Database -detailed".
    For technical information, type: "get-help Update-Database -full".

Updated