-
Notifications
You must be signed in to change notification settings - Fork 4k
Add Data Sync PowerShell Cmdlets to Azure.SQL #4037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@fhljys, |
Can one of the admins verify this patch? |
@akromm Hi Adam, could you please help review this one? Thanks a lot! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments, mainly looks good
function Get-SqlSyncGroupTestEnvironmentParameters ($testSuffix) | ||
{ | ||
return @{ | ||
intervalInSeconds = 300; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: bad indentation here due to tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix this. Thanks.
#> | ||
function Get-SqlSyncMemberTestEnvironmentParameters ($testSuffix) | ||
{ | ||
return @{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: bad indentation here due to tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix this.
/// <summary> | ||
/// Gets or sets the name of the server on which syncDB is hosted | ||
/// </summary> | ||
[Parameter(Mandatory = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make SyncDatabaseServerName and SyncDatabaseResourceGroupName non-mandatory, use the value of ServerName and ResourceGroupName by default? That way you don't have to specify it if sync agent server and sync db server are the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
&& MyInvocation.BoundParameters.ContainsKey("SyncDatabaseServerName") | ||
&& MyInvocation.BoundParameters.ContainsKey("SyncDatabaseName")) | ||
{ | ||
this.syncDatabaseId = string.Format("resourceGroups/{0}/providers/Microsoft.Sql/servers/{1}/databases/{2}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does "/subscriptions/{id}/
" prefix get added? can you comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was added in AzureSqlDataSyncCommunicator. I will add a comment in the code.
/// Gets or sets the frequency (in seconds) of doing data synchronization. | ||
/// </summary> | ||
[Parameter(Mandatory = false, HelpMessage = "The frequency (in seconds) of doing data synchronization. Default is -1, which means the auto synchronization is not enabled.")] | ||
public int? IntervalInSeconds { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, perhaps consider adding IntervalInMinutes, IntervalInHours as different parameter sets so that user doesn't need to do math
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your suggestions. This will be considered in future improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to use a TimeSpan interval?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its unit is seconds. It is more like a frequency than a time span.
} | ||
catch (Newtonsoft.Json.JsonReaderException) | ||
{ | ||
throw new PSArgumentException("The schema file is empty or invalid!", "SchemaFile"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide a link to a page that describes the expected schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The official doc is not published yet. Could we add this in next sprint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure.
/// Gets or sets the frequency (in seconds) of doing data synchronization. | ||
/// </summary> | ||
[Parameter(Mandatory = false, HelpMessage = "The frequency (in seconds) of doing data synchronization. Default is -1, which means the auto synchronization is not enabled.")] | ||
public int? IntervalInSeconds { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to be nullable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change it to int.
[Parameter(Mandatory = true, | ||
HelpMessage = "The database used to store sync related metadata.")] | ||
[ValidateNotNullOrEmpty] | ||
public string SyncDatabaseName { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you sort all of these so that the required parameters appear first in the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Thanks.
[Parameter(Mandatory = true, | ||
ParameterSetName = AzureSqlSet, | ||
HelpMessage = "The Azure SQL Server Name of the member database.")] | ||
public string MemberServerName { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please sort such that required parameters appear before optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
/// </summary> | ||
public override void ExecuteCmdlet() | ||
{ | ||
if (!Force.IsPresent && !ShouldProcess( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is already done here:
https://github.com/Azure/azure-powershell/blob/preview/src/ResourceManager/Sql/Commands.Sql/Common/AzureSqlCmdletBase.cs#L137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if (!Force.IsPresent && !ShouldProcess( | ||
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncMemberDescription, this.SyncMemberName, this.SyncGroupName), | ||
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.RemoveAzureSqlSyncMemberWarning, this.SyncMemberName, this.SyncGroupName), | ||
Microsoft.Azure.Commands.Sql.Properties.Resources.ShouldProcessCaption)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already done/covered by:
https://github.com/Azure/azure-powershell/blob/preview/src/ResourceManager/Sql/Commands.Sql/Common/AzureSqlCmdletBase.cs#L137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
/// Gets or sets the frequency (in seconds) of doing data synchronization | ||
/// </summary> | ||
[Parameter(Mandatory = false, HelpMessage = "The frequency (in seconds) of doing data synchronization. Default is -1, which means the auto synchronization is not enabled.")] | ||
public int? IntervalInSeconds { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be nullable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "The database type.")] | ||
[ValidateSet("AzureSqlDatabase", IgnoreCase = true)] | ||
public string DatabaseType { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter seems unnecessary. It is marked as mandatory and it can only have 1 value. Furthermore it is not used anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I will delete it.
/// <summary> | ||
/// Gets or sets the frequency (in seconds) time of doing data synchronization | ||
/// </summary> | ||
public int? IntervalInSeconds { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be nullable? What does it mean if this is null?
Additionally consider changing this to a TimeSpan object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The service layer will use the default value when this is null. It is the business logic requirement of service layer. I have changed Power Shell parameters to 'int' instead of 'int?'. Will keep it as it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is a server default this is appropriate. In PowerShell, you can make this parameter optional and check BoundParameters to see if the user provided it. Limiting the number of values that the user has to provide is a good thing
Tables = syncGroupSchemaTable | ||
}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove blank link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Thanks.
@akromm Hi Adam, I have updated this code to resolve your comments. Please help me review it again. |
@akromm Hi Adam, I pushed a commit to improve the help doc xml, which dismissed your signoff accidently. Could you please help me review this again. Very sorry for the trouble. Thanks a lot. |
@markcowl Please help me review the changes. Thanks. |
/// </summary> | ||
public override void ExecuteCmdlet() | ||
{ | ||
if (!Force.IsPresent && !ShouldProcess( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the correct way to implement ShouldProcess. This should be implemented as
{
if (Force || ShouldContinue)
{
<execute action>
You can get this behavior using ConfirmAction(bool, string, string, Action)
as well
{ | ||
return string.Format("{0}.{1}", this.ServerName, this.DatabaseName); | ||
if (!Force.IsPresent && !ShouldProcess( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
@@ -15507,6 +15507,14 @@ ResourceGroup01 Server01 DBAs 40b79501-b343-44ed-9ce7-da4c8cc7353b</d | |||
<maml:uri /></dev:type> | |||
<dev:defaultValue>False</dev:defaultValue> | |||
</command:parameter> | |||
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"><maml:name>Force</maml:name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file should not be included in the repo
@markcowl Hi Mark, please help review this one. Thank you very much! |
@markcowl @cormacpayne @azuresdkci Hi Mark and Team, the on demand run finished successfully. Is there anything need I do to finish this PR? Thanks a lot. |
Description
Azure SQL Data Sync is a new feature with a new set of REST API on the existing Azure SQL RP (Microsoft.Sql namespace). Data Sync feature is mainly used in two scenarios: one is sync schema between two Azure SQL databases, and the other is sync schema between an Azure SQL Database and an on-premises SQL server database. Currently, the REST API is in public review. And this PR is to add PowerShell Cmdlets for data sync feature.
This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.
General Guidelines
Testing Guidelines
Cmdlet Signature Guidelines
ShouldProcess
and haveSupportShouldProcess=true
specified in the cmdlet attribute. You can find more information onShouldProcess
here.OutputType
attribute if any output is produced - if the cmdlet produces no output, it should implement aPassThru
parameter.Cmdlet Parameter Guidelines