Replies: 1 comment
-
|
@devkeydet Here is a temporary PowerShell script refreshes the schemas by reading the databaseReferences object from power.config.json and running pac code add-data-source for each Dataverse table. # PowerShell Script: refresh-schemas.ps1
# Purpose: Scan power.config.json and refresh Dataverse schemas using pac CLI commands
# Define path to configuration file
# Try multiple possible locations to ensure compatibility
$configPath = Join-Path $PSScriptRoot "..\power.config.json"
if (-Not (Test-Path $configPath)) {
$configPath = Join-Path (Get-Location) "power.config.json"
}
# Check if configuration file exists
if (-Not (Test-Path $configPath)) {
Write-Error "Configuration file not found. Please ensure power.config.json exists in the project root or current directory."
exit 1
}
# Change working directory to project root to ensure pac CLI finds power.config.json
$projectRoot = Split-Path $configPath -Parent
Set-Location $projectRoot
Write-Host "Working directory set to project root: $projectRoot"
# Read and parse JSON configuration
try {
$configContent = Get-Content $configPath -Raw | ConvertFrom-Json
} catch {
Write-Error "Failed to parse power.config.json: $_"
exit 1
}
# Extract logicalName properties
$logicalNames = @()
# Handle nested structure under databaseReferences
if ($configContent.databaseReferences) {
foreach ($dbRef in $configContent.databaseReferences.PSObject.Properties) {
$dbValue = $dbRef.Value
if ($dbValue.dataSources) {
foreach ($source in $dbValue.dataSources.PSObject.Properties) {
$sourceValue = $source.Value
if ($sourceValue.logicalName) {
$logicalNames += $sourceValue.logicalName
}
}
}
}
} elseif ($configContent.dataSources) {
foreach ($source in $configContent.dataSources) {
if ($source.logicalName) {
$logicalNames += $source.logicalName
}
}
} else {
Write-Warning "No dataSources found in power.config.json"
}
# Refresh schemas using pac CLI
foreach ($name in $logicalNames) {
Write-Host "Refreshing schema for logicalName: $name"
$command = "pac code add-data-source -a dataverse -t $name"
try {
Invoke-Expression $command
Write-Host "Schema refreshed successfully for $name"
} catch {
Write-Error ("Failed to refresh schema for {0}: {1}" -f $name, $_)
}
}
Write-Host "Schema refresh process completed." |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
During the dev inner loop, it is common for add new columns to tables, delete columns, etc. It would be great to have a convenient command in
pacthat goes back to my data source(s) and regenerates the code. Ideally, I should have control of "all" vs the specific ones I want to regen.Beta Was this translation helpful? Give feedback.
All reactions