Exemple #1
0
        public void can_overwrite_the_logger()
        {
            var logger = new ConsoleMartenLogger();

            var options = new StoreOptions();

            options.Logger(logger);

            options.Logger().ShouldBeSameAs(logger);
        }
Exemple #2
0
        public void default_logger_is_the_nullo()
        {
            var options = new StoreOptions();

            options.Logger().ShouldBeOfType <NulloMartenLogger>();

            options.Logger(null);

            // doesn't matter, nullo is the default
            options.Logger().ShouldBeOfType <NulloMartenLogger>();
        }
Exemple #3
0
        public async Task ApplyAllConfiguredChangesToDatabaseAsync(AutoCreate?withCreateSchemaObjects = null)
        {
            var defaultAutoCreate = StoreOptions.AutoCreateSchemaObjects != AutoCreate.None
                ? StoreOptions.AutoCreateSchemaObjects
                : AutoCreate.CreateOrUpdate;

            var patch = await CreateMigrationAsync();

            if (patch.Difference == SchemaPatchDifference.None)
            {
                return;
            }

            using var conn = _tenant.CreateConnection();
            await conn.OpenAsync();

            try
            {
                var martenLogger = StoreOptions.Logger();
                await patch.ApplyAll(conn, DdlRules, withCreateSchemaObjects ?? defaultAutoCreate, sql => martenLogger.SchemaChange(sql));

                _tenant.MarkAllFeaturesAsChecked();
            }
            catch (Exception e)
            {
                throw new MartenSchemaException("All Configured Changes", patch.UpdateSql, e);
            }
        }
Exemple #4
0
        private void generateOrUpdateFeature(Type featureType, IFeatureSchema feature)
        {
            lock (_updateLock)
            {
                using (var conn = _factory.Create())
                {
                    conn.Open();

                    var patch = new SchemaPatch(_options.DdlRules);
                    patch.Apply(conn, _options.AutoCreateSchemaObjects, feature.Objects);
                    patch.AssertPatchingIsValid(_options.AutoCreateSchemaObjects);

                    var ddl = patch.UpdateDDL;
                    if (patch.Difference != SchemaPatchDifference.None && ddl.IsNotEmpty())
                    {
                        var cmd = conn.CreateCommand(ddl);
                        try
                        {
                            cmd.ExecuteNonQuery();
                            _options.Logger().SchemaChange(ddl);
                            RegisterCheck(featureType, feature);
                        }
                        catch (Exception e)
                        {
                            throw new MartenCommandException(cmd, e);
                        }
                    }
                    else if (patch.Difference == SchemaPatchDifference.None)
                    {
                        RegisterCheck(featureType, feature);
                    }
                }
            }
        }
Exemple #5
0
        public void ApplyAllConfiguredChangesToDatabase(AutoCreate?withCreateSchemaObjects = null)
        {
            var defaultAutoCreate = StoreOptions.AutoCreateSchemaObjects != AutoCreate.None
                ? StoreOptions.AutoCreateSchemaObjects
                : AutoCreate.CreateOrUpdate;

            var patch = ToPatch(true, withCreateSchemaObjects ?? defaultAutoCreate);
            var ddl   = patch.UpdateDDL.Trim();

            if (ddl.IsEmpty())
            {
                return;
            }

            try
            {
                _tenant.RunSql(ddl);
                StoreOptions.Logger().SchemaChange(ddl);

                _tenant.MarkAllFeaturesAsChecked();
            }
            catch (Exception e)
            {
                throw new MartenSchemaException("All Configured Changes", ddl, e);
            }
        }
        public void add_marten_by_store_options_with_custom_logger()
        {
            using var container = Container.For(x =>
            {
                x.AddMarten(provider => {
                    var options = new StoreOptions();
                    options.Connection(ConnectionSource.ConnectionString);
                    options.Logger(new TestOutputMartenLogger(null));
                    return(options);
                });
            });

            var store = container.GetRequiredService <IDocumentStore>();

            store.Options.Logger().ShouldBeOfType <TestOutputMartenLogger>();
        }
Exemple #7
0
        public void ApplyAllConfiguredChangesToDatabase()
        {
            var patch = ToPatch(true);
            var ddl   = patch.UpdateDDL.Trim();

            if (ddl.IsNotEmpty())
            {
                try
                {
                    _tenant.RunSql(ddl);
                    StoreOptions.Logger().SchemaChange(ddl);

                    _tenant.MarkAllFeaturesAsChecked();
                }
                catch (Exception e)
                {
                    throw new MartenSchemaException("All Configured Changes", ddl, e);
                }
            }
        }