public static SqlPreCommand DropIndex(ObjectName tableName, DiffIndex index)
 {
     if (index.ViewName == null)
     {
         return(DropIndex(tableName, index.IndexName));
     }
     else
     {
         return(DropViewIndex(new ObjectName(tableName.Schema, index.ViewName), index.IndexName));
     }
 }
Exemple #2
0
        public static SqlPreCommand DropIndex(ObjectName tableName, DiffIndex index)
        {
            if (index.IsPrimary)
            {
                return(AlterTableDropConstraint(tableName, new ObjectName(tableName.Schema, index.IndexName)));
            }

            if (index.ViewName == null)
            {
                return(DropIndex(tableName, index.IndexName));
            }
            else
            {
                return(DropViewIndex(new ObjectName(tableName.Schema, index.ViewName), index.IndexName));
            }
        }
Exemple #3
0
        public static SqlPreCommand ReCreateFreeIndex(ITable table, DiffIndex index, string oldTable, Dictionary <string, string> tableReplacements)
        {
            if (index.IsControlledIndex)
            {
                throw new InvalidOperationException("The Index is not a free index");
            }

            var onlyColumn = index.Columns.Only();

            string indexName = onlyColumn != null && index.IndexName.StartsWith("FIX_") ? "FIX_{0}_{1}".FormatWith(table.Name.Name, (tableReplacements.TryGetC(onlyColumn) ?? onlyColumn)) :
                               tableReplacements == null?index.IndexName.Replace(oldTable, table.Name.Name) :
                                   index.IndexName.Replace(tableReplacements).Replace(oldTable, table.Name.Name);

            string columns = index.Columns.ToString(c => (tableReplacements.TryGetC(c) ?? c).SqlEscape(), ", ");

            return(new SqlPreCommandSimple("CREATE INDEX {0} ON {1}({2})".FormatWith(
                                               indexName.SqlEscape(),
                                               table.Name,
                                               columns)));
        }
Exemple #4
0
        public static SqlPreCommand ReCreateFreeIndex(ITable table, DiffIndex index, string oldTable, Dictionary<string, string> tableReplacements)
        {
            if (index.IsControlledIndex)
                throw new InvalidOperationException("The Index is not a free index");

            var onlyColumn = index.Columns.Only();

            string indexName = onlyColumn != null && index.IndexName.StartsWith("FIX_") ? "FIX_{0}_{1}".Formato(table.Name.Name, (tableReplacements.TryGetC(onlyColumn) ?? onlyColumn)) :
                tableReplacements == null ? index.IndexName.Replace(oldTable, table.Name.Name) :
                index.IndexName.Replace(tableReplacements).Replace(oldTable, table.Name.Name);

            string columns = index.Columns.ToString(c => (tableReplacements.TryGetC(c) ?? c).SqlEscape(), ", ");

            return new SqlPreCommandSimple("CREATE INDEX {0} ON {1}({2})".Formato(
                 indexName.SqlEscape(),
                 table.Name,
                 columns));
        }
Exemple #5
0
 public static SqlPreCommand DropIndex(ObjectName tableName, DiffIndex index)
 {
     if (index.ViewName == null)
         return DropIndex(tableName, index.IndexName);
     else
         return DropViewIndex(new ObjectName(tableName.Schema, index.ViewName), index.IndexName);
 }
        public static SqlPreCommand DropIndex(ObjectName tableName, DiffIndex index)
        {
            if (index.IsPrimary)
                return AlterTableDropConstraint(tableName, new ObjectName(tableName.Schema, index.IndexName));

            if (index.ViewName == null)
                return DropIndex(tableName, index.IndexName);
            else
                return DropViewIndex(new ObjectName(tableName.Schema, index.ViewName), index.IndexName);
        }