Пример #1
0
        public override void Perform(SchemaChanges changes, IOutput output)
        {
            // This isn't really anything to do with pre-upgrade-hooks but there's no other good place to give this warning!
            foreach (var query in QueryType.AllFrom(changes.Current))
            {
                if (query.State != null && query.State.Body.StartsWith("<FAIL>"))
                {
                    output.Warning(query.State.Body.Substring(6));
                }
            }

            foreach (var hook in PreUpgradeHookType.AllFrom(changes.Current))
            {
                var proc = QueryType.GetFrom(changes.Current, hook.ParentIdentifier);
                if (proc.State == null || proc.State is QueryType.FunctionState || proc.State.Parameters.Any())
                {
                    output.Warning("Cannot execute pre-upgrade hook " + proc.Name + ": stored procedure does not exist or has parameters.");
                }

                changes.Put(changes.SchemaDriver.GetExecuteProcSql(hook.ParentName));

                if (changes.Desired.Get(hook) == null)
                {
                    changes.Remove(null, hook);
                }
            }
        }
Пример #2
0
        public override void Perform(SchemaChanges changes, IOutput output)
        {
            foreach (var desired in QueryType.AllFrom(changes.Desired))
            {
                var current = changes.Current.Get(desired);
                if (current != null && QueryType.IsEqual(current.State, desired.State, changes.DbDriver))
                {
                    continue;
                }

                if (desired.State != null)
                {
                    var    body       = desired.State.Body;
                    var    parameters = desired.State.Parameters;
                    string createSql;

                    var functionState = desired.State as QueryType.FunctionState;
                    if (functionState != null)
                    {
                        createSql = changes.SchemaDriver.GetCreateFunctionSql(desired.Name, parameters, functionState.ReturnType, body);
                    }
                    else
                    {
                        createSql = changes.SchemaDriver.GetCreateProcSql(desired.Name, parameters, body);
                    }

                    changes.Put(createSql, desired);
                }
                else
                {
                    if (current == null)
                    {
                        changes.Put(null, desired);
                    }
                }
            }

            // Restore all pre-upgrade-hooks corresponding to procedures that have been successfully updated.
            foreach (var upgradeHook in PreUpgradeHookType.AllFrom(changes.Desired))
            {
                var desiredProc = QueryType.GetFrom(changes.Desired, upgradeHook.ParentIdentifier);

                var currentProc = changes.Current.Get(desiredProc);
                if (currentProc != null && QueryType.IsEqual(currentProc.State, desiredProc.State, changes.DbDriver))
                {
                    changes.Put(null, upgradeHook);
                }
            }
        }