예제 #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);
        }
예제 #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);
        }
예제 #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)
            {
                string sql = "";
                Constraints.ForEach(item =>
                {
                    if (item.Type == Constraint.ConstraintType.ForeignKey)
                    {
                        sql += item.ToSqlAdd() + "\r\n";
                    }
                });
                listDiff.Add(ToSql(false), dependenciesCount, ScriptAction.AddTable);
                listDiff.Add(sql, 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);
        }
예제 #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.VersionTypeEnum.SQLServerAzure10;

            string sql   = "";
            string sqlPK = "";
            string sqlUC = "";
            string sqlFK = "";

            if (Columns.Any())
            {
                sql += "CREATE TABLE " + FullName + "\r\n(\r\n";
                sql += Columns.ToSql();
                if (Constraints.Any())
                {
                    sql += ",\r\n";
                    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 += sqlPK + sqlUC + sqlFK;
                    sql  = sql.Substring(0, sql.Length - 3) + "\r\n";
                }
                else
                {
                    sql += "\r\n";
                    if (!String.IsNullOrEmpty(CompressType))
                    {
                        sql += "WITH (DATA_COMPRESSION = " + CompressType + ")\r\n";
                    }
                }
                sql += ")";

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

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