protected override void Generate( AlterColumnOperation operation, IModel model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); DropDefaultConstraint(operation.Schema, operation.Table, operation.Name, builder); builder .Append("ALTER TABLE ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) .Append(" ALTER COLUMN "); ColumnDefinition( operation.Schema, operation.Table, operation.Name, operation.ClrType, operation.ColumnType, operation.IsUnicode, operation.MaxLength, operation.IsRowVersion, operation.IsNullable, /*defaultValue:*/ null, /*defaultValueSql:*/ null, operation.ComputedColumnSql, /*identity:*/ false, operation, model, builder); builder.AppendLine(SqlGenerationHelper.StatementTerminator); if ((operation.DefaultValue != null) || (operation.DefaultValueSql != null)) { builder .Append("ALTER TABLE ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) .Append(" ADD"); DefaultValue(operation.DefaultValue, operation.DefaultValueSql, builder); builder .Append(" FOR ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Name)) .AppendLine(SqlGenerationHelper.StatementTerminator); } EndStatement(builder); }
protected override void Generate(AlterColumnOperation operation, IModel model, RelationalCommandListBuilder builder) { }
protected override void Generate(AlterColumnOperation operation, IModel model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); // TODO: There is probably duplication here with other methods. See ColumnDefinition. //TODO: this should provide feature parity with the EF6 provider, check if there's anything missing for EF7 var type = operation.ColumnType; if (operation.ColumnType == null) { var property = FindProperty(model, operation.Schema, operation.Table, operation.Name); type = property != null ? TypeMapper.GetMapping(property).StoreType : TypeMapper.GetMapping(operation.ClrType).StoreType; } var serial = operation.FindAnnotation(MyCatAnnotationNames.Prefix + MyCatAnnotationNames.Serial); var isSerial = serial != null && (bool)serial.Value; var identifier = SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema); var alterBase = $"ALTER TABLE {identifier} MODIFY COLUMN {SqlGenerationHelper.DelimitIdentifier(operation.Name)}"; // TYPE builder.Append(alterBase) .Append(" ") .Append(type) .Append(operation.IsNullable ? " NULL" : " NOT NULL") .AppendLine(SqlGenerationHelper.StatementTerminator); alterBase = $"ALTER TABLE {identifier} ALTER COLUMN {SqlGenerationHelper.DelimitIdentifier(operation.Name)}"; builder.Append(alterBase); if (operation.DefaultValue != null) { builder.Append(" SET DEFAULT ") .Append(SqlGenerationHelper.GenerateLiteral((dynamic)operation.DefaultValue)) .AppendLine(SqlGenerationHelper.BatchTerminator); } else if (!string.IsNullOrWhiteSpace(operation.DefaultValueSql)) { builder.Append(" SET DEFAULT ") .Append(operation.DefaultValueSql) .AppendLine(SqlGenerationHelper.BatchTerminator); } else if (isSerial) { builder.Append(" SET DEFAULT "); switch (type) { case "smallint": case "int": case "bigint": case "real": case "double precision": case "numeric": //TODO: need function CREATE SEQUENCE IF NOT EXISTS and set to it... //Until this is resolved changing IsIdentity from false to true //on types int2, int4 and int8 won't switch to type serial2, serial4 and serial8 throw new NotImplementedException("Not supporting creating sequence for integer types"); case "char(38)": case "uuid": case "uniqueidentifier": builder.Append("UUID()"); break; default: throw new NotImplementedException($"Not supporting creating IsIdentity for {type}"); } } else { builder.Append(" DROP DEFAULT "); } }
protected override void Generate(AlterColumnOperation operation, IModel model, MigrationCommandListBuilder builder) { throw new NotSupportedException(SqliteStrings.InvalidMigrationOperation(operation.GetType().Name)); }