<commit_before>{
  "Id": "ActionTemplates-65",
  "Name": "Run Entity Framework migrations (Update-Database)",
  "Description": "Runs `Update-Database` to update the database to the latest Entity Framework migrations",
  "ActionType": "Octopus.Script",
  "Version": 9,
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "# A collection of functions that can be used by script steps to determine where packages installed\r\n# by previous steps are located on the filesystem.\r\n \r\nfunction Find-InstallLocations {\r\n    $result = @()\r\n    $OctopusParameters.Keys | foreach {\r\n        if ($_.EndsWith('].Output.Package.InstallationDirectoryPath')) {\r\n            $result += $OctopusParameters[$_]\r\n        }\r\n    }\r\n    return $result\r\n}\r\n \r\nfunction Find-InstallLocation($stepName) {\r\n    $result = $OctopusParameters.Keys | where {\r\n        $_.Equals(\"Octopus.Action[$stepName].Output.Package.InstallationDirectoryPath\",  [System.StringComparison]::OrdinalIgnoreCase)\r\n    } | select -first 1\r\n \r\n    if ($result) {\r\n        return $OctopusParameters[$result]\r\n    }\r\n \r\n    throw \"No install location found for step: $stepName\"\r\n}\r\n \r\nfunction Find-SingleInstallLocation {\r\n    $all = @(Find-InstallLocations)\r\n    if ($all.Length -eq 1) {\r\n        return $all[0]\r\n    }\r\n    if ($all.Length -eq 0) {\r\n        throw \"No package steps found\"\r\n    }\r\n    throw \"Multiple package steps have run; please specify a single step\"\r\n}\r\n\r\nfunction Test-LastExit($cmd) {\r\n    if ($LastExitCode -ne 0) {\r\n        Write-Host \"##octopus[stderr-error]\"\r\n        write-error \"$cmd failed with exit code: $LastExitCode\"\r\n    }\r\n}\r\n\r\n\r\n\r\n\r\n$stepName = $OctopusParameters['NugetPackageStepName']\r\n\r\n$stepPath = \"\"\r\nif (-not [string]::IsNullOrEmpty($stepName)) {\r\n    Write-Host \"Finding path to package step: $stepName\"\r\n    $stepPath = Find-InstallLocation $stepName\r\n} else {\r\n    $stepPath = Find-SingleInstallLocation\r\n}\r\nWrite-Host \"Package was installed to: $stepPath\"\r\n\r\n\r\n\r\n#Locate Migrate.exe\r\n$efToolsFolder = $OctopusParameters['EfToolsFolder']\r\n$migrateExe = Join-Path $efToolsFolder \"migrate.exe\"\r\nif (-Not(Test-Path $migrateExe)){\r\n\tthrow (\"Unable to locate migrate.exe file. Specifed path $migrateExe does not exist.\")\r\n}\r\nWrite-Host(\"Using Migrate.Exe from $migrateExe\")\r\n\r\n\r\n#Locate Assembly with DbContext class\r\n$contextDllName = $OctopusParameters['AssemblyDllName']\r\n$binPath = Join-Path $stepPath \"bin\"\r\n$contextDllPath = Join-Path $binPath $contextDllName\r\nif (-Not(Test-Path $contextDllPath)){\r\n\tthrow (\"Unable to locate assembly file with DbContext class. Specifed path $contextDllPath does not exist.\")\r\n}\r\nWrite-Host(\"Using $contextDllName from $contextDllPath\")\r\n\r\n#Locate web.config. Migrate.exe needs it for some reason, even if connection string is provided\r\n$webConfigPath = Join-Path $stepPath \"web.config\"\r\nif (-Not(Test-Path $webConfigPath)){\r\n\tthrow (\"Unable to locate web.config file. Specifed path $webConfigPath does not exist.\")\r\n}\r\n\r\n\r\n$connectionString = $OctopusParameters['ConnectionString']\r\n\r\n$migrateCommand = \"& \"\"$migrateExe\"\" \"\"$contextDllName\"\" /connectionString=\"\"$connectionString\"\" /connectionProviderName=\"\"System.Data.SqlClient\"\" /startupConfigurationFile=\"\"$webConfigPath\"\" /startUpDirectory=\"\"$binPath\"\" /Verbose\"\r\n\r\nWrite-Host \"##octopus[stderr-error]\"        # Stderr is an error\r\nWrite-Host \"Executing: \" $migrateCommand\r\nWrite-Host \r\n\r\nInvoke-Expression $migrateCommand | Write-Host\r\n\r\n"
  },
  "SensitiveProperties": {},
  "Parameters": [
    {
      "Name": "EfToolsFolder",
      "Label": "Path to EF Tools folder",
      "HelpText": "Please provide a full path to a folder where Migrate.exe (along with other EF files are contained, available from EF nuget package) on tentacle",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "NugetPackageStepName",
      "Label": "Site Path",
      "HelpText": "Name of the previously-deployed package step that contains the files with web.config and `/bin` folder",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "StepName"
      }
    },
    {
      "Name": "AssemblyDllName",
      "Label": "Name of Assembly file with EF-Context",
      "HelpText": "Please provide a name of the assembly file where EF-context is stored",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ConnectionString",
      "Label": "Connection String",
      "HelpText": "Connection string to the database where the migration should be applied.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    }
  ],
  "LastModifiedOn": "2015-03-25T08:44:38.238+00:00",
  "LastModifiedBy": "trailmax",
  "$Meta": {
    "ExportedAt": "2015-03-25T08:53:16.012Z",
    "OctopusVersion": "2.6.3.886",
    "Type": "ActionTemplate"
  }<commit_msg>Copy migrate.exe to ASP.NET project's bin folder and also replace connectionString by connectionStringName<commit_after>{
  "Id": "ActionTemplates-65",
  "Name": "Run Entity Framework migrations (Update-Database)",
  "Description": "Runs `Update-Database` to update the database to the latest Entity Framework migrations",
  "ActionType": "Octopus.Script",
  "Version": 4,
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "# A collection of functions that can be used by script steps to determine where packages installed\r\n# by previous steps are located on the filesystem.\r\n \r\nfunction Find-InstallLocations {\r\n    $result = @()\r\n    $OctopusParameters.Keys | foreach {\r\n        if ($_.EndsWith('].Output.Package.InstallationDirectoryPath')) {\r\n            $result += $OctopusParameters[$_]\r\n        }\r\n    }\r\n    return $result\r\n}\r\n \r\nfunction Find-InstallLocation($stepName) {\r\n    $result = $OctopusParameters.Keys | where {\r\n        $_.Equals(\"Octopus.Action[$stepName].Output.Package.InstallationDirectoryPath\",  [System.StringComparison]::OrdinalIgnoreCase)\r\n    } | select -first 1\r\n \r\n    if ($result) {\r\n        return $OctopusParameters[$result]\r\n    }\r\n \r\n    throw \"No install location found for step: $stepName\"\r\n}\r\n \r\nfunction Find-SingleInstallLocation {\r\n    $all = @(Find-InstallLocations)\r\n    if ($all.Length -eq 1) {\r\n        return $all[0]\r\n    }\r\n    if ($all.Length -eq 0) {\r\n        throw \"No package steps found\"\r\n    }\r\n    throw \"Multiple package steps have run; please specify a single step\"\r\n}\r\n\r\nfunction Test-LastExit($cmd) {\r\n    if ($LastExitCode -ne 0) {\r\n        Write-Host \"##octopus[stderr-error]\"\r\n        write-error \"$cmd failed with exit code: $LastExitCode\"\r\n    }\r\n}\r\n\r\n\r\n\r\n\r\n$stepName = $OctopusParameters['NugetPackageStepName']\r\n\r\n$stepPath = \"\"\r\nif (-not [string]::IsNullOrEmpty($stepName)) {\r\n    Write-Host \"Finding path to package step: $stepName\"\r\n    $stepPath = Find-InstallLocation $stepName\r\n} else {\r\n    $stepPath = Find-SingleInstallLocation\r\n}\r\nWrite-Host \"Package was installed to: $stepPath\"\r\n\r\n$binPath = Join-Path $stepPath \"bin\"\r\n\r\n#Locate Migrate.exe\r\n$efToolsFolder = $OctopusParameters['EfToolsFolder']\r\n$originalMigrateExe = Join-Path $efToolsFolder \"migrate.exe\"\r\n\r\nif (-Not(Test-Path $originalMigrateExe)){\r\n    throw (\"Unable to locate migrate.exe file. Specifed path $originalMigrateExe does not exist.\")\r\n}\r\nWrite-Host(\"Found Migrate.Exe from $originalMigrateExe\")\r\n\r\n# Move migrate.exe to ASP.NET Project's bin folder as per https://msdn.microsoft.com/de-de/data/jj618307.aspx?f=255&MSPPError=-2147217396\r\nCopy-Item $originalMigrateExe -Destination $binPath\r\n\r\n$migrateExe = Join-Path $binPath \"migrate.exe\"\r\nWrite-Host(\"Copied $originalMigrateExe into $binPath\")\r\n\r\n#Locate Assembly with DbContext class\r\n$contextDllName = $OctopusParameters['AssemblyDllName']\r\n$contextDllPath = Join-Path $binPath $contextDllName\r\nif (-Not(Test-Path $contextDllPath)){\r\n    throw (\"Unable to locate assembly file with DbContext class. Specifed path $contextDllPath does not exist.\")\r\n}\r\nWrite-Host(\"Using $contextDllName from $contextDllPath\")\r\n\r\n#Locate web.config. Migrate.exe needs it for some reason, even if connection string is provided\r\n$webConfigPath = Join-Path $stepPath \"web.config\"\r\nif (-Not(Test-Path $webConfigPath)){\r\n    throw (\"Unable to locate web.config file. Specifed path $webConfigPath does not exist.\")\r\n}\r\n\r\n$connectionStringName = $OctopusParameters['ConnectionStringName']\r\n\r\n$migrateCommand = \"& \"\"$migrateExe\"\" \"\"$contextDllName\"\" /connectionStringName=\"\"$connectionStringName\"\" /startupConfigurationFile=\"\"$webConfigPath\"\" /startUpDirectory=\"\"$binPath\"\" /Verbose\"\r\n\r\nWrite-Host \"##octopus[stderr-error]\"        # Stderr is an error\r\nWrite-Host \"Executing: \" $migrateCommand\r\nWrite-Host \r\n\r\nInvoke-Expression $migrateCommand | Write-Host\r\n\r\n",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline"
  },
  "Parameters": [
    {
      "Name": "EfToolsFolder",
      "Label": "Path to EF Tools folder",
      "HelpText": "Please provide a full path to a folder where Migrate.exe (along with other EF files are contained, available from EF nuget package) on tentacle",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "NugetPackageStepName",
      "Label": "Site Path",
      "HelpText": "Name of the previously-deployed package step that contains the files with web.config and `/bin` folder",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "StepName"
      }
    },
    {
      "Name": "AssemblyDllName",
      "Label": "Name of Assembly file with EF-Context",
      "HelpText": "Please provide a name of the assembly file where EF-context is stored",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ConnectionStringName",
      "Label": "ConnectionStringName",
      "HelpText": "Name of the key in <connectionStrings> section in Web.Config",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "$Meta": {
    "ExportedAt": "2016-09-20T07:45:17.818Z",
    "OctopusVersion": "3.3.6",
    "Type": "ActionTemplate"
  }
{'fraction_non_alphanumeric': 0.1675436167266685, 'fraction_numerical': 0.009138742730545555, 'mean_word_length': 3.4511092851273624, 'pattern_counts': {'":': 77, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3429566', 'n_tokens_mistral': 3766, 'n_tokens_neox': 3623, 'n_words': 823}