Skip to content

Commit

Permalink
Bringing rivet.ps1 up to current coding standards.
Browse files Browse the repository at this point in the history
  • Loading branch information
splatteredbits committed Apr 18, 2024
1 parent c3a8480 commit f0a5951
Showing 1 changed file with 52 additions and 77 deletions.
129 changes: 52 additions & 77 deletions Rivet/rivet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
A database migration tool for PowerShell.
.DESCRIPTION
Rivet is a database migration tool for SQL Server. Finally!
Rivet is a database migration tool for SQL Server. Finally!
This script is the entry point for Rivet. It is used to create a new migration, and apply/revert migrations against a database.
This script is the entry point for Rivet. It is used to create a new migration, and apply/revert migrations against a
database.
Called without any arguments, Rivet will shows this help topic.
Expand All @@ -31,9 +32,10 @@ Applies all migrations.
.EXAMPLE
rivet.ps1 -Push 'CreateTableStarships'
Demonstrates how to apply a named migration. Don't include the timestamp. Wildcards are permitted.
Demonstrates how to apply a named migration. Don't include the timestamp. Wildcards are permitted.
*Be careful with this syntax!* If the named migration(s) depend on other migrations that haven't been run, the migration will fail.
*Be careful with this syntax!* If the named migration(s) depend on other migrations that haven't been run, the
migration will fail.
.EXAMPLE
rivet.ps1 -Pop
Expand All @@ -43,98 +45,80 @@ Reverts the last migration script.
.EXAMPLE
rivet.ps1 -Pop 5
Demonstrates how to revert multiple migrations. The last `-Count` migrations will be popped.
Demonstrates how to revert multiple migrations. The last `-Count` migrations will be popped.
.EXAMPLE
rivet.ps1 -Pop 'AddTable'
Demonstrates how to pop a specific migration. Wildcards supported. Will match either the migration's name or ID.
Demonstrates how to pop a specific migration. Wildcards supported. Will match either the migration's name or ID.
.EXAMPLE
rivet.ps1 -Redo
Reverts the last migration script, then reapplies its. Equivalent to
Reverts the last migration script, then reapplies its. Equivalent to
rivet.ps1 -Pop
rivet.ps1 -Push
.EXAMPLE
rivet.ps1 -Push -Environment Production
Demonstrates how to migrate databases in a different environment. The `Production` environment should be specified in the `rivet.json` configuration file.
Demonstrates how to migrate databases in a different environment. The `Production` environment should be specified in
the `rivet.json` configuration file.
.EXAMPLE
rivet.ps1 -DropDatabase
Demonstrates how to drop the database(s) for the current environment. Using this switch will require confirmation from the user but it can be bypassed when given the -Force switch as well.
Demonstrates how to drop the database(s) for the current environment. Using this switch will require confirmation from
the user but it can be bypassed when given the -Force switch as well.
#>
#Requires -Version 3
[CmdletBinding(DefaultParameterSetName='ShowHelp', SupportsShouldProcess=$True)]
[CmdletBinding(DefaultParameterSetName='ShowHelp', SupportsShouldProcess)]
param(
[Parameter(Mandatory=$true,ParameterSetName='New')]
[Switch]
# Creates a new migration.
$New,
[Parameter(Mandatory, ParameterSetName='New')]
[switch] $New,

[Parameter(Mandatory=$true,ParameterSetName='Push')]
[Switch]
# Applies migrations.
$Push,
[Parameter(Mandatory, ParameterSetName='Push')]
[switch] $Push,

[Parameter(Mandatory=$true,ParameterSetName='Pop')]
[Parameter(Mandatory=$true,ParameterSetName='PopByCount')]
[Parameter(Mandatory=$true,ParameterSetName='PopByName')]
[Parameter(Mandatory=$true,ParameterSetName='PopAll')]
[Switch]
# Reverts migrations.
$Pop,
[Parameter(Mandatory, ParameterSetName='Pop')]
[Parameter(Mandatory, ParameterSetName='PopByCount')]
[Parameter(Mandatory, ParameterSetName='PopByName')]
[Parameter(Mandatory, ParameterSetName='PopAll')]
[switch] $Pop,

[Parameter(Mandatory=$true,ParameterSetName='Redo')]
[Switch]
# Reverts a migration, then re-applies it.
$Redo,

[Parameter(Mandatory=$true,ParameterSetName='New',Position=1)]
[Parameter(ParameterSetName='Push',Position=1)]
[Parameter(Mandatory=$true,ParameterSetName='PopByName',Position=1)]
[Parameter(Mandatory, ParameterSetName='Redo')]
[switch] $Redo,

# The name of the migrations to create, push, or pop. Matches against the migration's ID, Name, or file name
# (without extension). Wildcards permitted.
[Parameter(Mandatory, ParameterSetName='New', Position=1)]
[Parameter(ParameterSetName='Push', Position=1)]
[Parameter(Mandatory, ParameterSetName='PopByName', Position=1)]
[ValidateLength(1,241)]
[string[]]
# The name of the migrations to create, push, or pop. Matches against the migration's ID, Name, or file name (without extension). Wildcards permitted.
$Name,
[String[]] $Name,

[Parameter(Mandatory=$true,ParameterSetName='PopByCount',Position=1)]
[UInt32]
# The number of migrations to pop. Default is 1.
$Count = 1,
[Parameter(Mandatory, ParameterSetName='PopByCount', Position=1)]
[UInt32] $Count = 1,

[Parameter(Mandatory=$true,ParameterSetName='PopAll')]
[Switch]
# Pop all migrations
$All,
[Parameter(Mandatory, ParameterSetName='PopAll')]
[switch] $All,

[Parameter(ParameterSetName='Pop')]
[Parameter(ParameterSetName='PopByCount')]
[Parameter(ParameterSetName='PopByName')]
[Parameter(ParameterSetName='PopAll')]
[Parameter(ParameterSetName='DropDatabase')]
[Switch]
# Force popping a migration you didn't apply or that is old.
$Force,

[Parameter(ParameterSetName='New',Position=2)]
[Parameter(ParameterSetName='Push')]
[Parameter(ParameterSetName='Pop')]
[Parameter(ParameterSetName='PopByCount')]
[Parameter(ParameterSetName='PopByName')]
[Parameter(ParameterSetName='PopAll')]
[Parameter(ParameterSetName='Redo')]
[Parameter(ParameterSetName='DropDatabase')]
[Parameter(ParameterSetName='Checkpoint')]
[string[]]
# The database(s) to migrate. Optional. Will operate on all databases otherwise.
$Database,
[switch] $Force,

[Parameter(ParameterSetName='New')]
# The database(s) to migrate. Optional. Will operate on all databases otherwise.
[Parameter(ParameterSetName='New', Position=2)]
[Parameter(ParameterSetName='Push')]
[Parameter(ParameterSetName='Pop')]
[Parameter(ParameterSetName='PopByCount')]
Expand All @@ -143,34 +127,25 @@ param(
[Parameter(ParameterSetName='Redo')]
[Parameter(ParameterSetName='DropDatabase')]
[Parameter(ParameterSetName='Checkpoint')]
[string]
# The environment you're working in. Controls which settings Rivet loads from the `rivet.json` configuration file.
$Environment,
[String[]] $Database,

[Parameter(ParameterSetName='New')]
[Parameter(ParameterSetName='Push')]
[Parameter(ParameterSetName='Pop')]
[Parameter(ParameterSetName='PopByCount')]
[Parameter(ParameterSetName='PopByName')]
[Parameter(ParameterSetName='PopAll')]
[Parameter(ParameterSetName='Redo')]
[Parameter(ParameterSetName='DropDatabase')]
[Parameter(ParameterSetName='Checkpoint')]
[string]
# The path to the Rivet configuration file. Default behavior is to look in the current directory for a `rivet.json` file. See `about_Rivet_Configuration` for more information.
$ConfigFilePath,
# The environment you're working in. Controls which settings Rivet loads from the `rivet.json` configuration file.
[String] $Environment,

# The path to the Rivet configuration file. Default behavior is to look in the current directory for a `rivet.json`
# file. See `about_Rivet_Configuration` for more information.
[String] $ConfigFilePath,

[Parameter(ParameterSetName='DropDatabase')]
[Switch]
# Drops the database(s) for the current environment when given. User will be prompted for confirmation when used.
$DropDatabase,
[Parameter(ParameterSetName='DropDatabase')]
[switch] $DropDatabase,

[Parameter(ParameterSetName='Checkpoint')]
[Switch]
# Checkpoints the current state of the database so that it can be re-created.
$Checkpoint
[Parameter(ParameterSetName='Checkpoint')]
[switch] $Checkpoint
)

#Requires -Version 5.1
Set-StrictMode -Version Latest

if( $PSCmdlet.ParameterSetName -eq 'ShowHelp' )
Expand All @@ -183,4 +158,4 @@ if( $PSCmdlet.ParameterSetName -eq 'ShowHelp' )

Invoke-Rivet @PSBoundParameters

exit $error.Count
exit $Error.Count

0 comments on commit f0a5951

Please sign in to comment.