Repair D365BacpacModelFile - d365collaborative/d365fo.tools GitHub Wiki
Repair a bacpac model file
Repair-D365BacpacModelFile [-Path] <String> [[-OutputPath] <String>] [[-PathRepairSimple] <String>]
[[-PathRepairQualifier] <String>] [[-PathRepairReplace] <String>] [-KeepFiles] [-Force] [<CommonParameters>]
As the backend of the Azure SQL infrastructure keeps evolving, the bacpac file can contain invalid instructions while we are trying to import into a local SQL Server installation on a Tier1 environment
Repair-D365BacpacModelFile -Path C:\Temp\Base.xml -PathRepairSimple '' -PathRepairQualifier '' -PathRepairReplace 'C:\Temp\RepairBacpac.Replace.Custom.json'
This will only process the Replace section, as the other repair paths are empty - indicating to skip them. It will load the instructions from the 'C:\Temp\RepairBacpac.Replace.Custom.json' file and run those in the Replace section.
Repair-D365BacpacModelFile -Path C:\Temp\Base.xml -KeepFiles -Force
This will process all repair sections. It will keep the files in the temporary work directory, for the user to analyze the files further. It will Force overwrite the output file, if it exists already.
Path to the bacpac model file that you want to work against
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Path to where the repaired model file should be placed
The default value is going to create a file next to the Path (input) file, with the '-edited' name appended to it
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Path to the json file, that contains all the instructions to be executed in the "Simple" section
The default json file is part of the module, and can be located with the below command:
explorer.exe
- Look for the "RepairBacpac.Simple.json" file
Or you can see the latest version, online, inside the github repository: https://github.com/d365collaborative/d365fo.tools/tree/master/d365fo.tools/internal/misc/RepairBacpac.Simple.json
Simple means, that we can remove complex elements, based on some basic logic. E.g.
{ "Search": "<Element Type="SqlPermissionStatement"ms_db_configreader", "End": "</Element>*" }
"<Element Type="SqlPermissionStatement"ms_db_configreader" can identify below, and together with "</Element>*" - we know when to stop.
<Element Type="SqlPermissionStatement" Name="[Grant.Delete.Object].[ms_db_configreader].[dbo].[dbo].[AutotuneBase]"> <Property Name="Permission" Value="4" /> <Relationship Name="Grantee"> <Entry> <References Name="[ms_db_configreader]" /> </Entry> </Relationship> <Relationship Name="Grantor"> <Entry> <References ExternalSource="BuiltIns" Name="[dbo]" /> </Entry> </Relationship> <Relationship Name="SecuredObject"> <Entry> <References Name="[dbo].[AutotuneBase]" /> </Entry> </Relationship> </Element>
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: "$script:ModuleRoot\internal\misc\RepairBacpac.Simple.json"
Accept pipeline input: False
Accept wildcard characters: False
Path to the json file, that contains all the instructions to be executed in the "Qualifier" section
The default json file is part of the module, and can be located with the below command:
explorer.exe
- Look for the "RepairBacpac.Qualifier.json" file
Or you can see the latest version, online, inside the github repository: https://github.com/d365collaborative/d365fo.tools/tree/master/d365fo.tools/internal/misc/RepairBacpac.Qualifier.json
Qualifier means, that we can remove complex elements, based on some basic logic. E.g.
{ "Search": "<Element Type="SqlRoleMembership">", "Qualifier": "<References Name=ms_db_configwriter", "End": "</Element>*" }
"<Element Type="SqlRoleMembership">" can identify below, "<References Name=ms_db_configwriter" qualifies that we are locating the correct one and together with "</Element>*" - we know when to stop.
<Element Type="SqlRoleMembership"> <Relationship Name="Member"> <Entry> <References Name="[ms_db_configwriter]" /> </Entry> </Relationship> <Relationship Name="Role"> <Entry> <References ExternalSource="BuiltIns" Name="[db_ddladmin]" /> </Entry> </Relationship> </Element>
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: "$script:ModuleRoot\internal\misc\RepairBacpac.Qualifier.json"
Accept pipeline input: False
Accept wildcard characters: False
Path to the json file, that contains all the instructions to be executed in the "Replace" section
The default json file is part of the module, and can be located with the below command:
explorer.exe
- Look for the "RepairBacpac.Replace.json" file
Or you can see the latest version, online, inside the github repository: https://github.com/d365collaborative/d365fo.tools/tree/master/d365fo.tools/internal/misc/RepairBacpac.Replace.json
Replace means, that we can replace/remove strings, based on some basic logic. E.g.
{ "Search": "<Property Name="AutoDrop" Value="True" />", "Replace": "" }
"<Property Name="AutoDrop" Value="True" />" can identify below, and "" is the value we want to replace with it.
<Property Name="AutoDrop" Value="True" />
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 5
Default value: "$script:ModuleRoot\internal\misc\RepairBacpac.Replace.json"
Accept pipeline input: False
Accept wildcard characters: False
Instruct the cmdlet to keep the files from the repair process
The files are very large, so only use this as a way to analyze why your model file didn't end up in the desired state
Use it while you evolve/develop your instructions, but remove it from ANY full automation scripts
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Instruct the cmdlet to overwrite the file specified in the OutputPath if it already exists
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Author: Mötz Jensen (@Splaxi) Author: Florian Hopfner (@FH-Inway)
Json files has to be an array directly in the root of the file. All " (double quotes) has to be escaped with " - otherwise it will not work as intended.
This cmdlet is inspired by the work of "Brad Bateman" (github: @batetech)
His github profile can be found here: https://github.com/batetech
Florian Hopfner did a gist implementation, which has been used as the foundation for this implementation
The original gist is: https://gist.github.com/FH-Inway/f485c720b43b72bffaca5fb6c094707e
His github profile can be found here: https://github.com/FH-Inway