en-US/about_Rivet_Cookbook.help.txt
TOPIC
about_Rivet_Cookbooks SHORT DESCRIPTION Contains a bunch of recipes showing how to use Rivet. LONG DESCRIPTION ## How do I create my own operations? It is possible to create Rivet operations. Each operation must be in its own file. The name of the file must match the name of the operation, with a .ps1 extension. Put your custom operations in the `Operations` directory under the Rivet module. So, if you want to create a custom `Add-StandardTable` operation, you would create an `Operations\Add-StandardTable.ps1` file that looked like this: function Add-StandardTable { } Operations take no parameters. They should return one or more `Rivet.Operations.Operation` objects. See the `Rivet.Operations` namespace for available operations. ## How do I customize constraint/index names? ### Overview You can customize constraint/index names by writing a Rivet plug-in that modifies your constraint/index operation. See `about_Rivet_Plugins` for more information. Each operation that adds/removes a constraint has a `SetConstraintName(string)` method. You can check what kind of constraint is being added/removed with the `ConstraintType` property. You can check if an operation is a constraint operation by testing if it is a `Rivet.Operations.ConstraintOperation`. The add/remove index operation has a 'SetIndexName(string)' method. You can check if an operation is an index operation by testing if it is a `Rivet.Operations.IndexOperation` object. ### Examples function Update-ConstraintOrIndexName { [CmdletBinding()] [Rivet.Plugin([Rivet.Events]::BeforeOperationLoad)] param( [Parameter(Mandatory=$true)] [Rivet.Migration] # The migration the operation is part of. $Migration, [Parameter(Mandatory=$true)] [Rivet.Operations.Operation] # The operation which is about to be applied. $Operation ) Set-StrictMode -Version 'Latest' if( $Operation -is [Rivet.Operations.ConstraintOperation] ) { switch( $Operation.ConstraintType ) { [Rivet.ConstraintType]::Default { $Operation.Name = 'DF_{0}_{1}_{2}' -f $Operation.SchemaName,$Operation.TableName,$Operation.ColumnName } [Rivet.ConstraintType]::PrimaryKey { $Operation.Name = 'PK_{0}_{1}' -f $Operation.SchemaName,$Operation.TableName } [Rivet.ConstraintType]::ForeignKey { $Operation.Name = 'FK_{0}_{1}_{2}_{3}' -f $Operation.SchemaName,$Operation.TableName,$Operation.ReferencesSchemaName,$Operation.ReferencesTableName } [Rivet.ConstraintType]::Check { $Operation.Name = 'CK_{0}_{1}_{2}', $Operation.SchemaName,$Operation.TableName,($Operation.Expression -replace '[A-Za-z0-9]','') } [Rivet.ConstraintType]::UniqueKey { $Operation.Name = 'UK_{0}_{1}_{2}' -f$Operation.SchemaName,$Operation.TableName,($Operation.ColumnName -join '_') } default { throw ('Rivet has added a new constraint type that we don''t handle. Please update {0} to handle this new constraint type.' -f $PSCommandPath) } } } elseif( $Operation -is [Rivet.Operations.IndexOperation] ) { $prefix = 'IX' if( $Operation.Unique ) { $prefix = 'UIX' } $Operation.Name = '{0}_{1}_{2}_{3}' -f $prefix,$Operation.SchemaName,$Operation.TableName,($Operation.ColumnName -join '_') } } SEE ALSO about_Rivet_Plugins |