コード例 #1
0
ファイル: TableDelta.cs プロジェクト: JasperFx/weasel
        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());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
            });
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: TableDelta.cs プロジェクト: JasperFx/weasel
        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());
        }
コード例 #6
0
 public ObjectMigration(ISchemaObject schemaObject, SchemaPatchDifference difference)
 {
     SchemaObject = schemaObject;
     Difference   = difference;
 }
コード例 #7
0
        public void Log(ISchemaObject schemaObject, SchemaPatchDifference difference)
        {
            var migration = new ObjectMigration(schemaObject, difference);

            Migrations.Add(migration);
        }