예제 #1
0
        public IEnumerable <CommandGroup> CreateAlterRecreateIndices(IMetadata other, IComparerContext context)
        {
            var result = new CommandGroup();

            result.Append(SelectIndicesHelper(IndicesToBeCreatedPredicate, this, other, context).SelectMany(i => i.Create(Metadata, other, context)));
            result.Append(SelectIndicesHelper(IndicesToBeAlteredPredicate, this, other, context).SelectMany(i => i.Alter(Metadata, other, context)));
            result.Append(SelectIndicesHelper(IndicesToBeDropCreatedPredicate, this, other, context).SelectMany(i => DropCreateHelper(i, other, context)));
            result.Append(SelectIndicesHelper(IndicesToBeRecreatedPredicate, this, other, context).SelectMany(i => i.Create(Metadata, other, context)));
            if (!result.IsEmpty)
            {
                yield return(result);
            }
        }
    IEnumerable <CommandGroup> ISupportsComment.Handle(IMetadata other, IComparerContext context)
    {
        var result = new CommandGroup();

        if (Database.Description == null && other.MetadataDatabase.Database.Description != null)
        {
            result.Append(new Command().Append("COMMENT ON DATABASE IS NULL"));
        }
        else if (Database.Description != null && Database.Description != other.MetadataDatabase.Database.Description)
        {
            result.Append(new Command().Append($"COMMENT ON DATABASE IS '{SqlHelper.DoubleSingleQuotes(Database.Description)}'"));
        }

        if (!result.IsEmpty)
        {
            yield return(result);
        }
    }
예제 #3
0
        public IEnumerable <CommandGroup> DropIndices(IMetadata other, IComparerContext context)
        {
            var result = new CommandGroup();

            result.Append(SelectIndicesHelper(IndicesToBeDroppedPredicate, other.MetadataIndices, Metadata, context).SelectMany(i => i.Drop(Metadata, other, context)));
            if (!result.IsEmpty)
            {
                yield return(result);
            }
        }
    public IEnumerable <CommandGroup> HandleUserPrivileges(IMetadata other, IComparerContext context)
    {
        if (context.Settings.IgnorePermissions)
        {
            yield break;
        }

        var toRevoke = other.MetadataUserPrivileges.UserPrivileges.Except(UserPrivileges);
        var toGrant  = UserPrivileges.Except(other.MetadataUserPrivileges.UserPrivileges);
        var data     =
            toRevoke
            .Select(
                x => new
        {
            Privilege = x,
            Revoke    = true
        })
            .Concat(toGrant.Select(
                        x => new
        {
            Privilege = x,
            Revoke    = false
        }))
            .Where(x => !x.Privilege.IsSystemGeneratedObject)
            .GroupBy(x => x.Privilege.ObjectName);

        foreach (var group in data)
        {
            var result = new CommandGroup();
            foreach (var item in group)
            {
                var privilege = item.Privilege;
                var command   =
                    item.Revoke
                        ? CanCreateRevoke(privilege, context)
                              ? CreateRevoke(privilege, context)
                              : null
                        : CanCreateGrant(privilege, context)
                            ? CreateGrant(privilege, context)
                            : null;
                if (command != null && !command.IsEmpty)
                {
                    result.Append(command);
                }
            }
            if (!result.IsEmpty)
            {
                yield return(result);
            }
        }
    }
        public IEnumerable <CommandGroup> HandleConstraints(IMetadata other, IComparerContext context)
        {
            var batch = new CommandGroup();

            batch.Append(DropCheckConstraints(other, context));
            batch.Append(CreateCheckConstraints(other, context));
            batch.Append(DropConstraints(ForeignKeyConstraintPredicate, other, context));
            batch.Append(DropConstraints(PrimaryKeyConstraintPredicate, other, context));
            batch.Append(DropConstraints(UniqueConstraintPredicate, other, context));
            batch.Append(CreateConstraints(UniqueConstraintPredicate, other, context));
            batch.Append(CreateConstraints(PrimaryKeyConstraintPredicate, other, context));
            batch.Append(CreateConstraints(ForeignKeyConstraintPredicate, other, context));
            batch.Append(RecreateConstraintsDroppedAsReferenceConstraint(other, context));

            if (!batch.IsEmpty)
            {
                yield return(batch);
            }
        }
    public virtual CommandGroup ProcessDatabase(IMetadata other, IComparerContext context)
    {
        var result = new CommandGroup();

        if (Database.Dialect != 3 || other.MetadataDatabase.Database.Dialect != 3)
        {
            throw new NotSupportedException("Only Dialect 3 databases are supported.");
        }
        if (Database.CharacterSet.CharacterSetId != other.MetadataDatabase.Database.CharacterSet.CharacterSetId)
        {
            result.Append(SqlHelper.AlterDatabaseCharset(Database, other.MetadataDatabase.Database));
        }

        return(!result.IsEmpty ? result : null);
    }