RavenDB - Delete Database

Octopus.Script exported 2015-11-26 by timhunt303 belongs to ‘RavenDB’ category.

Used to delete a database from a server, with a possibility to remove all the data from hard drive.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

URL of the Raven Database

ravenDatabaseURL = http://localhost:8080/

The URL of the Raven database, where the Database is located.

For example http://localhost:8080/

Name of the Raven Database

ravenDatabaseName

Name of the Database in Raven.

Hard Delete

hardDelete = True

Should all of the data be removed from the hard drive as well

Allow Deletion

allowDelete

Is the database allowed to be deleted. TRUE OR FALSE value must be entered

For example: you don’t want a production server to be deleted, the script will stop it from happening

HINT: have a variable within Octopus that returns true if it is allowed to be deleted and vice versa.

Script body

Steps based on this template will execute the following PowerShell script.

#--------------------------------------------------------------------
#Octopus Variables

#URL where the database can be found
$ravenDatabaseURL = $OctopusParameters["ravenDatabaseURL"]

#Name of the Database
$ravenDatabaseName = $OctopusParameters["ravenDatabaseName"]

#hard delete (true or false)
$hardDelete = $OctopusParameters["hardDelete"]

#Allow Database to be deleted
$allowDelete = $OctopusParameters["allowDelete"]



Write-Output "`n-------------------------`n"
#--------------------------------------------------------------------
#checks to see if the database can be deleted

if($allowDelete -eq $FALSE)
{
    Write-Error "$ravenDatabaseName cannot be deleted. Please try this on a database that can be delete." -ErrorId E4
    Exit 1
}


#--------------------------------------------------------------------

#checks to see if the entered database exists, return a boolean value depending on the outcome
function doesRavenDBExist([string] $databaseChecking, [string]$URL)
{
    #retrieves the list of databases at the specified URL
    $database_list = Invoke-RestMethod -Uri "$URL/databases" -Method Get
    #checks if the database is at the specified URL
    if ($database_list -contains $databaseChecking.ToString()) 
    {
        return $TRUE
    }
    else 
    {
        return $FALSE
    }

    
}#ends does ravenDB exist function

Write-Output "`n-------------------------`n"


#--------------------------------------------------------------------

#check to see if database exists
Write-Output "Checking to see if $ravenDatabaseName exists"

$database_exists = doesRavenDBExist -databaseChecking $ravenDatabaseName -URL $ravenDatabaseURL

if($database_exists -eq $TRUE)
{
    Write-Output "$ravenDatabaseName exists"
    $doWork = $TRUE
}
else
{
    Write-Warning "$ravenDatabaseName does not exist already." 
    $doWork = $FALSE
}


Write-Output "`n-------------------------`n"


#--------------------------------------------------------------------
#hard delete option

$hardDeleteString = $hardDelete.ToString().ToLower()



#--------------------------------------------------------------------
#Delete database

if($doWork -eq $TRUE)
{

    Write-Output "Deleting Database: $ravenDatabaseName"

    $deleteURI = "$ravenDatabaseURL/admin/databases/$ravenDatabaseName" + "?hard-delete=$hardDeleteString"

    Invoke-RestMethod -Uri $deleteURI -Method Delete

    #Waits 10 seconds before it continues
    Start-Sleep -Seconds 10
    
    Write-Output "Database has successfuly been deleted"

}

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "474d4dff-e91b-4580-b074-c39763741cd6",
  "Name": "RavenDB - Delete Database",
  "Description": "Used to delete a database from a server, with a possibility to remove all the data from hard drive.",
  "Version": 8,
  "ExportedAt": "2015-11-26T03:54:46.614+00:00",
  "ActionType": "Octopus.Script",
  "Author": "timhunt303",
  "Parameters": [
    {
      "Name": "ravenDatabaseURL",
      "Label": "URL of the Raven Database",
      "HelpText": "The URL of the Raven database, where the Database is located. \n\nFor example **http://localhost:8080/**",
      "DefaultValue": "http://localhost:8080/",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ravenDatabaseName",
      "Label": "Name of the Raven Database",
      "HelpText": "Name of the Database in Raven.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "hardDelete",
      "Label": "Hard Delete",
      "HelpText": "Should all of the data be removed from the hard drive as well",
      "DefaultValue": "True",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      }
    },
    {
      "Name": "allowDelete",
      "Label": "Allow Deletion",
      "HelpText": "Is the database allowed to be deleted. **TRUE OR FALSE** value must be entered\n\n**For example**: you don't want a production server to be deleted, the script will stop it from happening\n\n**HINT**: have a variable within Octopus that returns true if it is allowed to be deleted and vice versa.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "#--------------------------------------------------------------------\n#Octopus Variables\n\n#URL where the database can be found\n$ravenDatabaseURL = $OctopusParameters[\"ravenDatabaseURL\"]\n\n#Name of the Database\n$ravenDatabaseName = $OctopusParameters[\"ravenDatabaseName\"]\n\n#hard delete (true or false)\n$hardDelete = $OctopusParameters[\"hardDelete\"]\n\n#Allow Database to be deleted\n$allowDelete = $OctopusParameters[\"allowDelete\"]\n\n\n\nWrite-Output \"`n-------------------------`n\"\n#--------------------------------------------------------------------\n#checks to see if the database can be deleted\n\nif($allowDelete -eq $FALSE)\n{\n    Write-Error \"$ravenDatabaseName cannot be deleted. Please try this on a database that can be delete.\" -ErrorId E4\n    Exit 1\n}\n\n\n#--------------------------------------------------------------------\n\n#checks to see if the entered database exists, return a boolean value depending on the outcome\nfunction doesRavenDBExist([string] $databaseChecking, [string]$URL)\n{\n    #retrieves the list of databases at the specified URL\n    $database_list = Invoke-RestMethod -Uri \"$URL/databases\" -Method Get\n    #checks if the database is at the specified URL\n    if ($database_list -contains $databaseChecking.ToString()) \n    {\n        return $TRUE\n    }\n    else \n    {\n        return $FALSE\n    }\n\n    \n}#ends does ravenDB exist function\n\nWrite-Output \"`n-------------------------`n\"\n\n\n#--------------------------------------------------------------------\n\n#check to see if database exists\nWrite-Output \"Checking to see if $ravenDatabaseName exists\"\n\n$database_exists = doesRavenDBExist -databaseChecking $ravenDatabaseName -URL $ravenDatabaseURL\n\nif($database_exists -eq $TRUE)\n{\n    Write-Output \"$ravenDatabaseName exists\"\n    $doWork = $TRUE\n}\nelse\n{\n    Write-Warning \"$ravenDatabaseName does not exist already.\" \n    $doWork = $FALSE\n}\n\n\nWrite-Output \"`n-------------------------`n\"\n\n\n#--------------------------------------------------------------------\n#hard delete option\n\n$hardDeleteString = $hardDelete.ToString().ToLower()\n\n\n\n#--------------------------------------------------------------------\n#Delete database\n\nif($doWork -eq $TRUE)\n{\n\n    Write-Output \"Deleting Database: $ravenDatabaseName\"\n\n    $deleteURI = \"$ravenDatabaseURL/admin/databases/$ravenDatabaseName\" + \"?hard-delete=$hardDeleteString\"\n\n    Invoke-RestMethod -Uri $deleteURI -Method Delete\n\n    #Waits 10 seconds before it continues\n    Start-Sleep -Seconds 10\n    \n    Write-Output \"Database has successfuly been deleted\"\n\n}"
  },
  "Category": "RavenDB",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/ravendb-delete-database.json",
  "Website": "/step-templates/474d4dff-e91b-4580-b074-c39763741cd6",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADBQTFRF0Y6OjR8iHx8fW1la0szNmVZZZB8k5crLkIyMwl1evI6QwrCw6uPjsiAh////8/HxjiSEkQAABNlJREFUeNrs24uWmyAUBVBQkKfh//+2gKiYGKMRsWkPnbUmdZLUPfeBEUoe/8gggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggADy/0GceDpgpDSM/SCE9L1SxMweK5swWu/5rdQKlDAUmTCmbZqkYb9UIzZR+p4INxxishlHa1xViBNC7H0Lo5RZvrafBrHDIdY2maUixJ+L2v0W/nxfD41D2cRtsiHtXwAhzz9aQlSMj1CvlDantLYSxPeevRArRHZW/cBymWR0LoJSOirHi51sZ9103lml9GooONssKdUhhszN9CEI2apWn1pJmqdXP7zELtKraVlliHot563ZfQyZJYQo6hV0CtOTpDG1IfRACoqeqrxrJMpwzC0hTVsT4vTTTJFlmf0YHyF8VMIflSZHuWxf7q5iz19Me5F6nNJb7WGQ6LXmV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O+M/iwECCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACSM3xR4ABAI1fHCI0qDDgAAAAAElFTkSuQmCC",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Thursday, November 26, 2015