Ejemplo n.º 1
0
        public override ISchemaBase Clone(ISchemaBase parent)
        {
            FullTextIndex index = new FullTextIndex(parent);

            index.ChangeTrackingState = this.ChangeTrackingState;
            index.FullText            = this.FullText;
            index.Name       = this.Name;
            index.FileGroup  = this.FileGroup;
            index.Id         = this.Id;
            index.Index      = this.Index;
            index.IsDisabled = this.IsDisabled;
            index.Status     = this.Status;
            index.Owner      = this.Owner;
            index.Columns    = this.Columns;
            this.ExtendedProperties.ForEach(item => index.ExtendedProperties.Add(item));
            return(index);
        }
Ejemplo n.º 2
0
        public Boolean Compare(FullTextIndex destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            if (!this.ChangeTrackingState.Equals(destination.ChangeTrackingState))
            {
                return(false);
            }
            if (!this.FullText.Equals(destination.FullText))
            {
                return(false);
            }
            if (!this.Index.Equals(destination.Index))
            {
                return(false);
            }
            if (this.IsDisabled != destination.IsDisabled)
            {
                return(false);
            }
            if (this.Columns.Count != destination.Columns.Count)
            {
                return(false);
            }
            if (this.Columns.Exists(item => { return(!destination.Columns.Exists(item2 => item2.ColumnName.Equals(item.ColumnName))); }))
            {
                return(false);
            }
            if (destination.Columns.Exists(item => { return(!this.Columns.Exists(item2 => item2.ColumnName.Equals(item.ColumnName))); }))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /*
         *      private SQLScriptList BuildSQLFileGroup()
         *      {
         *          var listDiff = new SQLScriptList();
         *
         *          Boolean found = false;
         *          Index clustered = Indexes.Find(item => item.Type == Index.IndexTypeEnum.Clustered);
         *          if (clustered == null)
         *          {
         *              foreach (Constraint cons in Constraints)
         *              {
         *                  if (cons.Index.Type == Index.IndexTypeEnum.Clustered)
         *                  {
         *                      listDiff.Add(cons.ToSqlDrop(FileGroup), dependenciesCount, ScripActionType.DropConstraint);
         *                      listDiff.Add(cons.ToSqlAdd(), dependenciesCount, ScripActionType.AddConstraint);
         *                      found = true;
         *                  }
         *              }
         *              if (!found)
         *              {
         *                  Status = ObjectStatusType.RebuildStatus;
         *                  listDiff = ToSqlDiff();
         *              }
         *          }
         *          else
         *          {
         *              listDiff.Add(clustered.ToSqlDrop(FileGroup), dependenciesCount, ScripActionType.DropIndex);
         *              listDiff.Add(clustered.ToSqlAdd(), dependenciesCount, ScripActionType.AddIndex);
         *          }
         *          return listDiff;
         *      }
         */

        /// <summary>
        /// Devuelve el schema de diferencias de la tabla en formato SQL.
        /// </summary>
        public override SQLScriptList ToSqlDiff(ICollection <ISchemaBase> schemas)
        {
            var listDiff = new SQLScriptList();

            if (Status != ObjectStatus.Original)
            {
                if (((Database)Parent).Options.Ignore.FilterTable)
                {
                    RootParent.ActionMessage.Add(this);
                }
            }

            if (Status == ObjectStatus.Drop)
            {
                if (((Database)Parent).Options.Ignore.FilterTable)
                {
                    listDiff.Add(ToSqlDrop(), dependenciesCount, ScriptAction.DropTable);
                    listDiff.AddRange(ToSQLDropFKBelow());
                }
            }
            if (Status == ObjectStatus.Create)
            {
                var sql = new StringBuilder();
                Constraints.ForEach(item =>
                {
                    if (item.Type == Constraint.ConstraintType.ForeignKey)
                    {
                        sql.AppendLine(item.ToSqlAdd());
                    }
                });
                listDiff.Add(ToSql(false), dependenciesCount, ScriptAction.AddTable);
                listDiff.Add(sql.ToString(), dependenciesCount, ScriptAction.AddConstraintFK);
            }
            if (HasState(ObjectStatus.RebuildDependencies))
            {
                GenerateDependencies();
                listDiff.AddRange(ToSQLDropDependencies());
                listDiff.AddRange(Columns.ToSqlDiff(schemas));
                listDiff.AddRange(ToSQLCreateDependencies());
                listDiff.AddRange(Constraints.ToSqlDiff());
                listDiff.AddRange(Indexes.ToSqlDiff());
                listDiff.AddRange(Options.ToSqlDiff());
                listDiff.AddRange(Triggers.ToSqlDiff());
                listDiff.AddRange(CLRTriggers.ToSqlDiff());
                listDiff.AddRange(FullTextIndex.ToSqlDiff());
            }
            if (HasState(ObjectStatus.Alter))
            {
                listDiff.AddRange(Columns.ToSqlDiff(schemas));
                listDiff.AddRange(Constraints.ToSqlDiff());
                listDiff.AddRange(Indexes.ToSqlDiff());
                listDiff.AddRange(Options.ToSqlDiff());
                listDiff.AddRange(Triggers.ToSqlDiff());
                listDiff.AddRange(CLRTriggers.ToSqlDiff());
                listDiff.AddRange(FullTextIndex.ToSqlDiff());
            }
            if (HasState(ObjectStatus.Rebuild))
            {
                GenerateDependencies();
                listDiff.AddRange(ToSQLRebuild());
                listDiff.AddRange(Columns.ToSqlDiff());
                listDiff.AddRange(Constraints.ToSqlDiff());
                listDiff.AddRange(Indexes.ToSqlDiff());
                listDiff.AddRange(Options.ToSqlDiff());
                //Como recrea la tabla, solo pone los nuevos triggers, por eso va ToSQL y no ToSQLDiff
                listDiff.Add(Triggers.ToSql(), dependenciesCount, ScriptAction.AddTrigger);
                listDiff.Add(CLRTriggers.ToSql(), dependenciesCount, ScriptAction.AddTrigger);
                listDiff.AddRange(FullTextIndex.ToSqlDiff());
            }
            if (HasState(ObjectStatus.Disabled))
            {
                listDiff.Add(ToSqlChangeTracking(), 0, ScriptAction.AlterTableChangeTracking);
            }
            return(listDiff);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Devuelve el schema de la tabla en formato SQL.
        /// </summary>
        public string ToSql(Boolean showFK)
        {
            Database    database = null;
            ISchemaBase current  = this;

            while (database == null && current.Parent != null)
            {
                database = current.Parent as Database;
                current  = current.Parent;
            }

            if (database == null)
            {
                return(string.Empty);
            }

            var isAzure10 = database.Info.Version == DatabaseInfo.SQLServerVersion.SQLServerAzure10;

            var    sql   = new StringBuilder();
            string sqlPK = "";
            string sqlUC = "";
            string sqlFK = "";

            if (Columns.Any())
            {
                sql.AppendLine("CREATE TABLE " + FullName + "\r\n(");
                sql.Append(Columns.ToSql());
                if (Constraints.Any())
                {
                    sql.AppendLine(",");
                    Constraints.AsQueryable()
                    // Add the constraint if it's not in DropStatus
                    .Where(c => !c.HasState(ObjectStatus.Drop))
                    .ToList()
                    .ForEach(item =>
                    {
                        if (item.Type == Constraint.ConstraintType.PrimaryKey)
                        {
                            sqlPK += "\t" + item.ToSql() + ",\r\n";
                        }
                        if (item.Type == Constraint.ConstraintType.Unique)
                        {
                            sqlUC += "\t" + item.ToSql() + ",\r\n";
                        }
                        if (showFK && item.Type == Constraint.ConstraintType.ForeignKey)
                        {
                            sqlFK += "\t" + item.ToSql() + ",\r\n";
                        }
                    });
                    sql.Append(sqlPK + sqlUC + sqlFK);
                    sql = new StringBuilder(sql.ToString(0, sql.Length - 3)).AppendLine();
                }
                else
                {
                    sql.AppendLine();
                    if (!String.IsNullOrEmpty(CompressType))
                    {
                        sql.AppendLine("WITH (DATA_COMPRESSION = " + CompressType + ")");
                    }
                }
                sql.Append(")");

                if (!isAzure10)
                {
                    if (!String.IsNullOrEmpty(FileGroup))
                    {
                        sql.Append(" ON [" + FileGroup + "]");
                    }

                    if (!String.IsNullOrEmpty(FileGroupText))
                    {
                        if (HasBlobColumn)
                        {
                            sql.Append(" TEXTIMAGE_ON [" + FileGroupText + "]");
                        }
                    }
                    if ((!String.IsNullOrEmpty(FileGroupStream)) && (HasFileStream))
                    {
                        sql.Append(" FILESTREAM_ON [" + FileGroupStream + "]");
                    }
                }
                sql.AppendLine();
                sql.AppendLine("GO");
                Constraints.ForEach(item =>
                {
                    if (item.Type == Constraint.ConstraintType.Check)
                    {
                        sql.AppendLine(item.ToSqlAdd());
                    }
                });
                if (HasChangeTracking)
                {
                    sql.Append(ToSqlChangeTracking());
                }
                sql.Append(Indexes.ToSql());
                sql.Append(FullTextIndex.ToSql());
                sql.Append(Options.ToSql());
                sql.Append(Triggers.ToSql());
            }
            return(sql.ToString());
        }