Exemple #1
0
        private SchemaChanges(DatabaseState current, DatabaseState desired, SchemaConnection connection, IOutput output, SchemaChangeOptions options, StateStorage storage)
        {
            this.current    = current;
            this.desired    = desired;
            this.connection = connection;
            this.output     = output;
            this.options    = options;
            this.storage    = storage;

            this.isUpgrade = current.Contains(CompletionType.Create());
        }
Exemple #2
0
        private void performBeforeStatements(string stepIdentifier, IOutput output)
        {
            if (HasFailed)
            {
                return;
            }

            // The guarantees made about the ordering of before statements are:
            // - Before statements on the stame step for the same parent object will execute together
            // - Before statements on the same step for the same parent object will execute in the order they were defined on that object
            // In an ideal world there would be no guarantees about the ordering of before statements between different top level objects, but
            // old versions of nrdo happened to process top-level objects in a specific order (tables in alphabetical order, followed by queries in
            // alphabetical order) and we have some code that relies on that ordering, so we need to continue to follow it.

            var beforeStatements = (from statement in BeforeStatementType.AllFrom(desired)
                                    where statement.State.Step == stepIdentifier && !current.Contains(statement)
                                    orderby statement.State.ParentSortKey, statement.State.SortPositionWithinParent
                                    select statement).ToImmutableList();

            using (var progress = output.ProgressBlock(beforeStatements.Count))
            {
                foreach (var statement in beforeStatements)
                {
                    var shouldProcess = isUpgrade ? statement.State.IsRunOnUpgrade : statement.State.IsRunOnInitialCreate;
                    if (shouldProcess)
                    {
                        doStepAction();
                        progress.Verbose(statement.ParentIdentifier + " before " + stepIdentifier + " " + statement.Name + ":");
                        Put(statement.State.Sql, statement);
                        if (HasFailed)
                        {
                            return;
                        }
                    }
                    else
                    {
                        Put(null, statement);
                    }
                    progress.Step++;
                }
            }
        }