protected override SchemaPatchDifference compare(Table expected, Table actual) { if (actual == null) { return(SchemaPatchDifference.Create); } Columns = new ItemDelta <TableColumn>(expected.Columns, actual.Columns); Indexes = new ItemDelta <IndexDefinition>(expected.Indexes, actual.Indexes, (e, a) => e.Matches(a, Expected)); ForeignKeys = new ItemDelta <ForeignKey>(expected.ForeignKeys, actual.ForeignKeys); PrimaryKeyDifference = SchemaPatchDifference.None; if (expected.PrimaryKeyName.IsEmpty()) { if (actual.PrimaryKeyName.IsNotEmpty()) { PrimaryKeyDifference = SchemaPatchDifference.Update; } } else if (actual.PrimaryKeyName.IsEmpty()) { PrimaryKeyDifference = SchemaPatchDifference.Create; } else if (!expected.PrimaryKeyColumns.SequenceEqual(actual.PrimaryKeyColumns)) { PrimaryKeyDifference = SchemaPatchDifference.Update; } return(determinePatchDifference()); }
public void should_not_throw_exception_on_assertion(SchemaPatchDifference difference, AutoCreate autoCreate) { var patch = new SchemaPatch(new DdlRules()); var table1 = new Table(new DbObjectName("public", "sometable1")); patch.Log(table1, difference); patch.AssertPatchingIsValid(autoCreate); }
public void should_throw_exception_on_assertion(SchemaPatchDifference difference, AutoCreate autoCreate) { var patch = new SchemaPatch(new DdlRules()); var table1 = new Table(new DbObjectName("public", "sometable1")); patch.Log(table1, difference); Exception <InvalidOperationException> .ShouldBeThrownBy(() => { patch.AssertPatchingIsValid(autoCreate); }); }
private ISchemaObjectDelta deltaFor(SchemaPatchDifference difference) { var delta = Substitute.For <ISchemaObjectDelta>(); delta.Difference.Returns(difference); var schemaObject = Substitute.For <ISchemaObject>(); delta.SchemaObject.Returns(schemaObject); return(delta); }
private SchemaPatchDifference determinePatchDifference() { if (Actual.PartitionStrategy != Expected.PartitionStrategy) { return(SchemaPatchDifference.Invalid); } if (!Actual.PartitionExpressions.SequenceEqual(Expected.PartitionExpressions)) { return(SchemaPatchDifference.Invalid); } if (!HasChanges()) { return(SchemaPatchDifference.None); } // If there are any columns that are different and at least one cannot // automatically generate an `ALTER TABLE` statement, the patch is invalid if (Columns.Different.Any(x => !x.Expected.CanAlter(x.Actual))) { return(SchemaPatchDifference.Invalid); } // If there are any missing columns and at least one // cannot generate an `ALTER TABLE * ADD COLUMN` statement if (Columns.Missing.Any(x => !x.CanAdd())) { return(SchemaPatchDifference.Invalid); } var differences = new SchemaPatchDifference[] { Columns.Difference(), ForeignKeys.Difference(), Indexes.Difference(), PrimaryKeyDifference }; return(differences.Min()); }
public ObjectMigration(ISchemaObject schemaObject, SchemaPatchDifference difference) { SchemaObject = schemaObject; Difference = difference; }
public void Log(ISchemaObject schemaObject, SchemaPatchDifference difference) { var migration = new ObjectMigration(schemaObject, difference); Migrations.Add(migration); }