Beispiel #1
0
        protected override IEnumerable <Command> OnCreate(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
        {
            if (IsUserCreatedIndex)
            {
                var command = new Command();
                command
                .Append($"CREATE {(Unique ? "UNIQUE " : string.Empty)}{(Descending ? "DESCENDING" : "ASCENDING")} INDEX {IndexName.AsSqlIndentifier()}")
                .AppendLine()
                .Append($"    ON {RelationName.AsSqlIndentifier()}");
                if (ExpressionSource == null)
                {
                    command.Append($"({string.Join(",", Segments.Select(s => s.FieldName.AsSqlIndentifier()))})");
                }
                else
                {
                    command.Append($" COMPUTED BY {ExpressionSource}");
                }

                yield return(command);

                if (Inactive)
                {
                    yield return(HandleIndexActiveInactive(context));
                }
            }
        }
Beispiel #2
0
 private Command HandleIndexActiveInactive(IComparerContext context)
 {
     return(new Command()
            .Append($"ALTER INDEX {IndexName.AsSqlIndentifier()} {(Inactive ? "INACTIVE" : "ACTIVE")}"));
 }
Beispiel #3
0
    private string AddConstraintUsingIndex(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
    {
        var builder = new StringBuilder();

        if (RelationConstraintType == RelationConstraintType.PrimaryKey || RelationConstraintType == RelationConstraintType.ForeignKey || RelationConstraintType == RelationConstraintType.Unique)
        {
            if (ConstraintName != IndexName && !SqlHelper.HasSystemPrefix(IndexName) || Index.Descending)
            {
                builder
                .AppendLine()
                .Append($"  USING {(Index.Descending ? "DESCENDING" : "ASCENDING")} INDEX {IndexName.AsSqlIndentifier()}");
            }
        }
        return(builder.ToString());
    }