Ejemplo n.º 1
0
 private static void CheckDatatypeInteger(Column old, Column @new, ColumnMetaChange metaChange)
 {
     if (old.Precision != @new.Precision)
     {
         metaChange.Set(ColumnChanges.Length);
     }
 }
Ejemplo n.º 2
0
 private static void CheckDatatypeString(Column old, Column @new, ColumnMetaChange metaChange)
 {
     if (old.CharacterMaxLength != @new.CharacterMaxLength)
     {
         metaChange.Set(ColumnChanges.Length);
     }
 }
Ejemplo n.º 3
0
        // TODO: Not near all necessary checks are made. We have to decide how much to track and which flags to set on said changes.
        private static void CheckDatatype(Column old, Column @new, ColumnMetaChange metaChange)
        {
            if (old.DataType != @new.DataType)
            {
                metaChange.Set(ColumnChanges.DataType);
            }

            switch (@new.DataType)
            {
            // Integers
            case SqlDataType.TinyInt:
            case SqlDataType.SmallInt:
            case SqlDataType.Int:
            case SqlDataType.BigInt:
                CheckDatatypeInteger(old, @new, metaChange);
                break;

            // Strings/chars
            case SqlDataType.Char:
            case SqlDataType.NChar:
            case SqlDataType.NText:
            case SqlDataType.NVarChar:
            case SqlDataType.NVarCharMax:
            case SqlDataType.Text:
            case SqlDataType.VarChar:
            case SqlDataType.VarCharMax:
                CheckDatatypeString(old, @new, metaChange);
                break;


            // Date and time
            case SqlDataType.SmallDateTime:
            case SqlDataType.Timestamp:
            case SqlDataType.Date:
            case SqlDataType.Time:
            case SqlDataType.DateTimeOffset:
            case SqlDataType.DateTime2:
            case SqlDataType.DateTime:
                break;

            // Bit/binary
            case SqlDataType.VarBinaryMax:
            case SqlDataType.VarBinary:
            case SqlDataType.Binary:
            case SqlDataType.Bit:
                break;

            // Float/decimal
            case SqlDataType.Float:
            case SqlDataType.Decimal:
                break;

            // Money / precise
            case SqlDataType.Real:
            case SqlDataType.SmallMoney:
            case SqlDataType.Numeric:
            case SqlDataType.Money:
                break;
            }
        }
Ejemplo n.º 4
0
 private static void CheckRename(Column old, Column @new, ColumnMetaChange metaChange)
 {
     if (!old.Name.Equals(@new.Name))
     {
         metaChange.Set(ColumnChanges.Rename);
     }
 }
Ejemplo n.º 5
0
 private static void CheckDeletion(Column old, Column @new, ColumnMetaChange metaChange)
 {
     if (@new == null)
     {
         metaChange.Set(ColumnChanges.Deletion);
     }
 }
Ejemplo n.º 6
0
 private static void CheckAddition(Column old, Column @new, ColumnMetaChange metaChange)
 {
     if (old == null)
     {
         metaChange.Set(ColumnChanges.Addition);
     }
 }
Ejemplo n.º 7
0
 private static void CheckUnique(Column old, Column @new, ColumnMetaChange metaChange)
 {
     if (old.IsUnique && [email protected])
     {
         metaChange.Set(ColumnChanges.NonUnique);
     }
     else if (!old.IsUnique && @new.IsUnique)
     {
         metaChange.Set(ColumnChanges.Unique);
     }
 }
Ejemplo n.º 8
0
 private static void CheckPrimaryKey(Column old, Column @new, ColumnMetaChange metaChange)
 {
     if (old.IsPrimaryKey && [email protected])
     {
         metaChange.Set(ColumnChanges.NonPrimary);
     }
     else if (!old.IsPrimaryKey && @new.IsPrimaryKey)
     {
         metaChange.Set(ColumnChanges.PrimaryKey);
     }
 }
Ejemplo n.º 9
0
 private static void CheckNullable(Column old, Column @new, ColumnMetaChange metaChange)
 {
     // Check if changed to non-nullable
     if (old.IsNullable && [email protected])
     {
         metaChange.Set(ColumnChanges.NonNull);
     }
     else if (!old.IsNullable && @new.IsNullable)
     {
         metaChange.Set(ColumnChanges.Nullable);
     }
 }
Ejemplo n.º 10
0
        private static ColumnMetaChange DetectChanges(Column old, Column @new)
        {
            var metaChange = new ColumnMetaChange(old, @new);

            CheckAddition(old, @new, metaChange);
            CheckDeletion(old, @new, metaChange);

            // Check if added or removed. If that is the case, a rename wouldn't make any sense.
            if (metaChange.IsSet(ColumnChanges.Addition | ColumnChanges.Deletion))
            {
                return(metaChange);
            }

            CheckRename(old, @new, metaChange);
            CheckDatatype(old, @new, metaChange);
            CheckNullable(old, @new, metaChange);
            CheckPrimaryKey(old, @new, metaChange);
            CheckUnique(old, @new, metaChange);

            return(metaChange);
        }
Ejemplo n.º 11
0
 private static void CheckDatatypeDateTime(Column old, Column @new, ColumnMetaChange metaChange)
 {
 }