public when_doing_a_schema_diff_with_no_changes_95_style()
        {
            var store1 = TestingDocumentStore.For(_ =>
            {
                _.DatabaseSchemaName = Marten.StoreOptions.DefaultDatabaseSchemaName;
                _.Schema.For <User>().Duplicate(x => x.UserName).Duplicate(x => x.Internal);
            });

            store1.Schema.EnsureStorageExists(typeof(User));


            // Don't use TestingDocumentStore because it cleans everything upfront.
            store2 = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
                _.DatabaseSchemaName = Marten.StoreOptions.DefaultDatabaseSchemaName;
                _.Schema.For <User>().Duplicate(x => x.UserName).Duplicate(x => x.Internal);
            });

            mapping = store2.Schema.MappingFor(typeof(User)).As <DocumentMapping>();
            diff    = mapping.SchemaObjects.As <DocumentSchemaObjects>().CreateSchemaDiff(store2.Schema);
        }
Esempio n. 2
0
        /// <summary>
        ///     compares the schemas of the two data tables, and returns any differences.  The master datatable must have primary
        ///     keys to be comparable.
        /// </summary>
        /// <returns></returns>
        public ReturnValue<SchemaDiff> CompareSchema()
        {
            if (!_master.PrimaryKey.Any())
            {
                return ReturnValue<SchemaDiff>.FailResult("Primary key is missing.");
            }

            var diff = new SchemaDiff { IsCompatible = true };

           
            if (MissingFieldNames.Any())
            {
                diff.ColumnDiffs.AddRange(MissingFieldNames.Select(name => new ColumnDiff
                {
                    Column = _master.Columns.Cast<DataColumn>().First(col => col.ColumnName == name),
                    DiffType = DiffType.Missing
                }));
                diff.IsCompatible = false;
            }

           
            diff.ColumnDiffs.AddRange(ExtraFieldNames.Select(
                colName => new ColumnDiff
                {
                    Column = _replica.Columns.Cast<DataColumn>().First(col => col.ColumnName == colName),
                    DiffType = DiffType.Extra
                }));

            // naive type checking - an difference in type breaks compatibilty.
            IEnumerable<ColumnDiff> diffCols =
                from masterCol in _master.Columns.Cast<DataColumn>()
                join repCol in _replica.Columns.Cast<DataColumn>() on masterCol.ColumnName equals repCol.ColumnName
                where masterCol.DataType != repCol.DataType
                select new ColumnDiff
                {
                    DiffType = DiffType.TypeMismatch,
                    Column = repCol
                };

            if (diffCols.Any())
            {
                diff.IsCompatible = false;
                diff.ColumnDiffs.AddRange(diffCols);
            }
            return ReturnValue<SchemaDiff>.SuccessResult(diff);
        }