Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephengodbold/4498778 to your computer and use it in GitHub Desktop.
Save stephengodbold/4498778 to your computer and use it in GitHub Desktop.
#requires -Version 2.0
param(
[Parameter(Mandatory=$true)]
[string]
$databaseRootDirectory
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 'Latest'
$fileGroupSpecification = "ON [PRIMARY]"
$fileGroupSpecificationPattern = "ON \[PRIMARY\]"
function Test-FileGroupSpecification {
param(
[Parameter(Mandatory=$true)]
[string]
$tablePath
)
Get-ChildItem $tablePath -Recurse -File -Exclude *table.sql | foreach {
$content = Get-Content $_.PSPath | Out-String
if ($content -match $fileGroupSpecificationPattern ) {
return $true
}
}
return $false
}
$tableScripts = Get-ChildItem $databaseRootDirectory -Recurse -Filter *.table.sql
$tableScripts | foreach {
$content = Get-Content $_.PSPath | Out-String
if ($content -match $fileGroupSpecificationPattern) {
if (Test-FileGroupSpecification $_.PSParentPath) {
$updatedContent = $content.Replace($fileGroupSpecification, '')
Set-Content $tableFilePath -Value $updatedContent
}
}
}
@stephengodbold
Copy link
Author

This gist is intended to work on the file structure of a .table.sql file with a separate file for the indexes. It will not resolve where indexes are stored in the table file at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment