/// <summary>
        /// Schedule an update by adding the appropriate delete, update and add records
        /// </summary>
		/// <param name="context">The installation context.</param>
        /// <param name="schemaObject">The object to update.</param>
		private void ScriptUpdate(InstallContext context, SchemaObject schemaObject)
        {
			// if we are dropping and readding an object, then make sure we put the object in the drop list at the right time
			if (schemaObject.OriginalOrder == 0)
			{
				// if the object matches an existing schema object (probably), then find it and copy its installation order
				var originalObject = context.SchemaObjects.Find(o => schemaObject.SchemaObjectType == o.SchemaObjectType && String.Compare(schemaObject.Name, o.Name, StringComparison.OrdinalIgnoreCase) == 0);
				if (originalObject != null)
					schemaObject.OriginalOrder = originalObject.OriginalOrder;
				else if (context.AddObjects.Any())
					schemaObject.OriginalOrder = context.AddObjects.Max(o => o.OriginalOrder) + 1;
				else
					schemaObject.OriginalOrder = 1;
			}

			// if we have already scripted this object, then don't do it again
			if (context.AddObjects.Any(o => o.Name == schemaObject.Name))
				return;

			// if this is a table, then let's see if we can just modify the table
			if (schemaObject.SchemaObjectType == SchemaObjectType.Table)
			{
				ScriptStandardDependencies(context, schemaObject);
				ScriptTableUpdate(context, schemaObject);
				return;
			}

			// add the object to the add queue before anything that depends on it, as well as any permissions on the object
			context.AddObjects.Add(schemaObject);

			// don't log any of our scripting
			ScriptPermissions(context, schemaObject);
			ScriptStandardDependencies(context, schemaObject);

			// handle dependencies for different types of objects
			if (schemaObject.SchemaObjectType == SchemaObjectType.IndexedView)
			{
				ScriptIndexes(context, schemaObject);
			}
			else if (schemaObject.SchemaObjectType == SchemaObjectType.PrimaryKey)
			{
				ScriptForeignKeys(context, schemaObject);
				ScriptXmlIndexes(context, schemaObject);
			}
			else if (schemaObject.SchemaObjectType == SchemaObjectType.PrimaryXmlIndex)
			{
				ScriptXmlIndexes(context, schemaObject);
			}
			else if (schemaObject.SchemaObjectType == SchemaObjectType.Index)
			{
				ScriptIndexes(context, schemaObject);
			}

			// drop the object after any dependencies are dropped
			SchemaRegistryEntry dropEntry = context.SchemaRegistry.Find(schemaObject.Name);
			if (dropEntry == null)
			{
				dropEntry = new SchemaRegistryEntry()
				{
					Type = schemaObject.SchemaObjectType,
					ObjectName = schemaObject.Name
				};
			}

			context.DropObjects.Add(dropEntry);
        }
		/// <summary>
		/// Compares two registry entry objects to determine the appropriate installation order.
		/// </summary>
		/// <param name="e1">The first object to compare.</param>
		/// <param name="e2">The second object to compere.</param>
		/// <returns>The comparison result.</returns>
		private static int CompareByInstallOrder(SchemaRegistryEntry e1, SchemaRegistryEntry e2)
		{
			int compare = e1.Type.CompareTo(e2.Type);
			if (compare == 0)
				compare = e1.OriginalOrder.CompareTo(e2.OriginalOrder);
			if (compare == 0)
				compare = String.Compare(e1.ObjectName, e2.ObjectName, StringComparison.OrdinalIgnoreCase);

			return compare;
		}