DeploymentPlanModifier

DeploymentPlanModifier

本文介绍了实现等效的< IgnoreUsers>使用DeploymentPlanModifier的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello

现在人们担心GenerateDropsIfNotInProject会丢弃角色和用户。许多DBA并没有好好看待这个问题,并且在这个论坛上报道了超过

 

There is an existing concern over the fact that GenerateDropsIfNotInProject will drop Roles and Users. This isn't looked on kindly by many DBAs and was reported on this forum overtwo years ago. 

使用
DeploymentPlanModifier 从计划中删除某些类型元素的DROP?如果有的话,是否有任何提示/片段可以让我们沿着这条道路缓和?

Is it feasible to implement a workaround using a DeploymentPlanModifier which removes DROPs from the plan for certain types of element? If so, are there any hints/snippets which can be provided to ease us along this path?

感谢您提供任何信息!

Marc

推荐答案

 


	[DatabaseSchemaProviderCompatibility(typeof(SqlDatabaseSchemaProvider))]
	public class SkipDropUser: DeploymentPlanModifier {

		protected override void OnExecute(DeploymentPlanContributorContext context) {

			// loop thru deployment plan steps
			if (context != null) {
				// find the first step in the plan
				DeploymentStep nextStep = context.PlanHandle.Head;
				// loop thru all the steps
				while (nextStep != null) {
					DeploymentStep currentStep = nextStep;
					nextStep = currentStep.Next;
					// if we are dropping a database object
					DropElementStep dropStep = currentStep as DropElementStep;
					if (dropStep != null) {
						// retrieve the SQL object that current step is dropping
						IModelElement sourceElement = dropStep.TargetElement;
						// if we are dropping a user
						if (context.Source.DatabaseSchemaProvider.UserInteractionServices.GetElementTypeDescription(sourceElement.ElementClass) == "User")
							// remove step from plan
							base.Remove(context.PlanHandle, dropStep);
					}
				}
			}
		}
	}


这篇关于实现等效的< IgnoreUsers>使用DeploymentPlanModifier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 23:28