in EntityFramework/src/MySqlMigrationSqlGenerator.cs [659:723]
protected virtual string Generate(ColumnModel op)
{
TypeUsage typeUsage = _providerManifest.GetStoreType(op.TypeUsage);
StringBuilder sb = new StringBuilder();
string type = op.StoreType;
if (type == null)
{
type = MySqlProviderServices.Instance.GetColumnType(typeUsage);
}
sb.Append(type);
if (!type.EndsWith(")", StringComparison.InvariantCulture))
{
if ((op.ClrType == typeof(string)) ||
((op.ClrType == typeof(byte) || op.ClrType == typeof(byte[])) && op.ClrType.IsArray))
{
if (op.MaxLength.HasValue)
{
sb.AppendFormat("({0}) ", op.MaxLength.Value);
}
}
if (op.Precision.HasValue && op.Scale.HasValue)
{
sb.AppendFormat("( {0}, {1} ) ", op.Precision.Value, op.Scale.Value);
}
else
{
if (type == "datetime" || type == "timestamp" || type == "time")
{
if (op.Precision.HasValue && op.Precision.Value >= 1)
{
sb.AppendFormat("({0}) ", op.Precision.Value <= 6 ? op.Precision.Value : 6);
}
if (op.IsIdentity && (String.Compare(type, "datetime", true) == 0 || String.Compare(type, "timestamp", true) == 0))
{
sb.AppendFormat(" DEFAULT CURRENT_TIMESTAMP{0}", op.Precision.HasValue && op.Precision.Value >= 1 ? "( " + op.Precision.Value.ToString() + " )" : "");
}
}
}
}
op.StoreType = type;
if (!(op.IsNullable ?? true))
{
sb.Append(string.Format("{0} not null ",
((!primaryKeyCols.Contains(op.Name) && op.IsIdentity && op.Type != PrimitiveTypeKind.Guid) ? " unsigned" :
((op.Type == PrimitiveTypeKind.Guid) ? " default '' " : ""))));
}
if (op.IsIdentity && (new string[] { "tinyint", "smallint", "mediumint", "int", "bigint" }).Contains(type.ToLower()))
{
sb.Append(" auto_increment ");
autoIncrementCols.Add(op.Name);
}
else
{
// nothing
}
if (!string.IsNullOrEmpty(op.DefaultValueSql))
{
sb.Append(string.Format(" default {0}", op.DefaultValueSql));
}
return sb.ToString();
}