예제 #1
0
 public EventStoreAdmin(IDocumentSchema schema, IConnectionFactory connectionFactory, StoreOptions options, ISerializer serializer)
 {
     _schema = schema;
     _connectionFactory = connectionFactory;
     _options = options;
     _serializer = serializer;
 }
예제 #2
0
 public static void OwnershipToTable(this IDDLRunner runner, StoreOptions options, TableName table)
 {
     if (options.OwnerName.IsNotEmpty())
     {
         runner.Apply(table, $"ALTER TABLE {table.QualifiedName} OWNER TO {options.OwnerName};");
     }
 }
예제 #3
0
        public MartenRegistryTests()
        {
            var storeOptions = new StoreOptions();
            storeOptions.Schema.Include<TestRegistry>();

            theSchema = new DocumentSchema(storeOptions, new ConnectionSource(), new NulloMartenLogger());
        }
예제 #4
0
        public void event_name_for_event_type()
        {
            var options = new StoreOptions();
            var mapping = new EventMapping<MembersJoined>(new EventGraph(options));

            mapping.EventTypeName.ShouldBe("members_joined");
        }
예제 #5
0
 public SequenceFactory(IDocumentSchema schema, IConnectionFactory factory, StoreOptions options, IMartenLogger logger)
 {
     _schema = schema;
     _factory = factory;
     _options = options;
     _logger = logger;
 }
예제 #6
0
        public SystemFunction(StoreOptions options, string functionName)
        {
            _function = new FunctionName(options.DatabaseSchemaName, functionName);
            _dropSql = $"drop function if exists {options.DatabaseSchemaName}.mt_immutable_timestamp cascade";

            Name = functionName;
        }
예제 #7
0
        public UpdateBatch(StoreOptions options, ISerializer serializer, IManagedConnection connection)
        {
            _options = options;
            _serializer = serializer;

            _commands.Push(new BatchCommand(serializer));
            Connection = connection;
        }
예제 #8
0
        public UpdateBatch(StoreOptions options, ISerializer serializer, ICommandRunner runner)
        {
            _options = options;
            _serializer = serializer;
            _runner = runner;

            _commands.Push(new BatchCommand(serializer));
        }
예제 #9
0
        public SystemFunction(StoreOptions options, string functionName, string args)
        {
            _args = args;
            _function = new FunctionName(options.DatabaseSchemaName, functionName);
            _dropSql = $"drop function if exists {options.DatabaseSchemaName}.{functionName}({args}) cascade";

            Name = functionName;
        }
예제 #10
0
        public static string GetJavascript(StoreOptions options, string jsfile)
        {
            if (options == null) throw new ArgumentNullException(nameof(options));

            var name = $"{typeof (SchemaBuilder).Namespace}.SQL.{jsfile}.js";

            return ReadFromStream(name, options.DatabaseSchemaName);
        }
예제 #11
0
        private void writeOwnership(StoreOptions options, SchemaPatch patch)
        {
            if (options.OwnerName.IsEmpty()) return;

            var ownership = Expected.ToOwnershipCommand(options.OwnerName);

            patch.Updates.Apply(this, ownership);
        }
예제 #12
0
        public TransformFunction(StoreOptions options, string name, string body)
        {
            _options = options;
            Name = name;
            Body = body;

            Function = new FunctionName(_options.DatabaseSchemaName, $"{Prefix}{Name.ToLower().Replace(".", "_")}");
        }
예제 #13
0
        public void CreatePatch(StoreOptions options, SchemaPatch patch)
        {
            TableDiff.CreatePatch(_mapping, patch);

            FunctionDiff.WritePatch(options, patch);

            IndexChanges.Each(x => patch.Updates.Apply(this, x));
            IndexRollbacks.Each(x => patch.Rollbacks.Apply(this, x));
        }
        public void can_override_with_MartenRegistry()
        {
            var storeOptions = new StoreOptions();
            storeOptions.Schema.For<Organization>().Duplicate(x => x.Time2, pgType: "timestamp");

            var schema = new DocumentSchema(storeOptions, null, new NulloMartenLogger());

            schema.MappingFor(typeof(Organization)).As<DocumentMapping>().DuplicatedFields.Single(x => x.MemberName == "Time2")
                .PgType.ShouldBe("timestamp");
        }
예제 #15
0
        public HiloSequence(IConnectionFactory factory, StoreOptions options, string entityName, HiloSettings settings)
        {
            _factory = factory;
            _options = options;
            _entityName = entityName;

            CurrentHi = -1;
            CurrentLo = 1;
            MaxLo = settings.MaxLo;
        }
예제 #16
0
        public UpdateBatch(StoreOptions options, ISerializer serializer, IManagedConnection connection, VersionTracker versions)
        {
            if (versions == null) throw new ArgumentNullException(nameof(versions));

            _options = options;
            _serializer = serializer;
            Versions = versions;

            _commands.Push(new BatchCommand(serializer));
            Connection = connection;
        }
예제 #17
0
        public void create_function_for_file()
        {
            var options = new StoreOptions();
            var func = TransformFunction.ForFile(options, _getFullnameJs);

            func.Name.ShouldBe("get_fullname");

            func.Body.ShouldContain("module.exports");

            func.Function.Name.ShouldBe("mt_transform_get_fullname");
        }
        public void should_get_foreign_key_from_registry()
        {
            var storeOptions = new StoreOptions();
            storeOptions.Schema.For<Issue>().ForeignKey<User>(i => i.OtherUserId);

            var schema = new DocumentSchema(storeOptions, null, null);

            schema.MappingFor(typeof(Issue))
                .As<DocumentMapping>()
                .ForeignKeys
                .ShouldContain(x => x.ColumnName == "other_user_id");
        }
예제 #19
0
        public HiloSequenceTests()
        {
            _container.GetInstance<DocumentCleaner>().CompletelyRemoveAll();

            var storeOptions = new StoreOptions();
            var sql = SchemaBuilder.GetSqlScript(storeOptions.DatabaseSchemaName, "mt_hilo");

            var connectionFactory = _container.GetInstance<IConnectionFactory>();
            connectionFactory.RunSql(sql);
            
            _theSequence = new HiloSequence(connectionFactory, storeOptions, "foo", new HiloSettings());
        }
예제 #20
0
        public EventQueryMapping(StoreOptions storeOptions) : base(typeof(IEvent), storeOptions)
        {
            Selector = new EventSelector(storeOptions.Events, storeOptions.Serializer());
            DatabaseSchemaName = storeOptions.Events.DatabaseSchemaName;

            Table = new TableName(DatabaseSchemaName, "mt_events");

            duplicateField(x => x.Sequence, "seq_id");
            duplicateField(x => x.StreamId, "stream_id");
            duplicateField(x => x.Version, "version");
            duplicateField(x => x.Timestamp, "timestamp");
        }
        public void Generate(StoreOptions options, string[] schemaNames)
        {
            if (schemaNames == null) throw new ArgumentNullException(nameof(schemaNames));

            var sql = GenerateScript(options, schemaNames);
            if (sql != null)
            {
                using (var runner = _advanced.OpenConnection())
                {
                    runner.Execute(sql);
                }
            }
        }
        private static void WriteSql(StoreOptions options, string databaseSchemaName, TextWriter writer)
        {
            writer.WriteLine($@"
    IF NOT EXISTS(
        SELECT schema_name
          FROM information_schema.schemata
          WHERE schema_name = '{databaseSchemaName}'
      )
    THEN
      EXECUTE 'CREATE SCHEMA {databaseSchemaName}';
    END IF;
");

        }
예제 #23
0
        public void picks_up_the_schema_from_storeoptions()
        {
            var options = new StoreOptions
            {
                DatabaseSchemaName = "other"
            };

            var func = new TransformFunction(options, "nfl.team.chiefs",
                "module.exports = function(doc){return doc;};");


            func.Function.Schema.ShouldBe("other");

        }
예제 #24
0
        public new static IDocumentStore For(Action<StoreOptions> configure)
        {
            var options = new StoreOptions();
            options.Connection(ConnectionSource.ConnectionString);
            options.Serializer<TestsSerializer>();


            configure(options);

            

            var store = new TestingDocumentStore(options);
            store.Advanced.Clean.CompletelyRemoveAll();

            return store;
        }
예제 #25
0
        public void write_patch_with_designated_owner()
        {
            var func = new FunctionBody(new FunctionName("public", "mt_upsert_target"), new string[0], theFunctionBody);


            var patch = new SchemaPatch();

            var options = new StoreOptions { OwnerName = "bill" };

            var diff = new FunctionDiff(func, null);

            diff.WritePatch(options, patch);

            patch.UpdateDDL.ShouldContain("ALTER FUNCTION public.mt_upsert_target(jsonb, character varying, uuid, uuid) OWNER TO \"bill\";");

        }
        public static string GenerateScript(StoreOptions options, IEnumerable<string> schemaNames)
        {
            if (schemaNames == null) throw new ArgumentNullException(nameof(schemaNames));

            var names = schemaNames
                 .Distinct()
                 .Where(name => name != StoreOptions.DefaultDatabaseSchemaName).ToList();

            if (!names.Any()) return null ;

            using (var writer = new StringWriter())
            {
                WriteSql(options, names, writer);

                return writer.ToString();
            }
        }
예제 #27
0
        public void write_patch_without_designated_owner()
        {
            var func = new FunctionBody(new FunctionName("public", "mt_upsert_target"), new string[0], theFunctionBody);


            var patch = new SchemaPatch();

            var options = new StoreOptions {OwnerName = null};

            var diff = new FunctionDiff(func, null);

            diff.WritePatch(options, patch);

            patch.UpdateDDL.ShouldNotContain("OWNER TO");


        }
예제 #28
0
        public static CommandExecutor For(StoreOptions options, Action<CommandFactory> configure)
        {
            var executor = CommandExecutor.For(factory =>
            {
                factory.RegisterCommands(typeof(MartenCommands).GetTypeInfo().Assembly);
                configure(factory);
                factory.ConfigureRun = run =>
                {
                    if (!(run.Input is MartenInput)) return;

                    run.Input.As<MartenInput>().Options = options;
                };

            });


            return executor;
        }
        private static void WriteSql(StoreOptions options, string databaseSchemaName, TextWriter writer)
        {
            writer.WriteLine($@"
    IF NOT EXISTS(
        SELECT schema_name
          FROM information_schema.schemata
          WHERE schema_name = '{databaseSchemaName}'
      )
    THEN
      EXECUTE 'CREATE SCHEMA {databaseSchemaName}';
    END IF;
");

            if (options.OwnerName.IsNotEmpty())
            {
                writer.WriteLine($"ALTER SCHEMA {databaseSchemaName} OWNER TO \"{options.OwnerName}\";");
            }
        }
예제 #30
0
        public new static IDocumentStore For(Action<StoreOptions> configure)
        {
            var options = new StoreOptions();
            options.Connection(ConnectionSource.ConnectionString);

            lock (_locker)
            {
                //options.DatabaseSchemaName = "Test_" + SchemaCount++;
            }
            

            configure(options);

            var store = new TestingDocumentStore(options);
            store.Advanced.Clean.CompletelyRemoveAll();

            return store;
        }
예제 #31
0
 public TransformSchema(StoreOptions options)
 {
     _options = options;
 }
예제 #32
0
 internal static void ConfigurePayments(this StoreOptions options)
 {
     // Snapshots
     options.Events.Projections.SelfAggregate <Payment>();
 }
예제 #33
0
 public bool IsActive(StoreOptions options) => _events.Any() || Projections.Any();
예제 #34
0
 public DefaultTenancy(IConnectionFactory factory, StoreOptions options) : base(options)
 {
     Default = new Tenant(options.Storage, options, factory, DefaultTenantId);
     Cleaner = new DocumentCleaner(options, Default);
     Schema  = new TenantSchema(options, Default.As <Tenant>());
 }
예제 #35
0
 public bool IsActive(StoreOptions options) => true;
예제 #36
0
 public override void GenerateCodeToSetDbParameterValue(GeneratedMethod method, GeneratedType type, int i, Argument parameters,
                                                        DocumentMapping mapping, StoreOptions options)
 {
     method.Frames.Code($"{{0}}[{{1}}].Value = _tenantId;", parameters, i);
     method.Frames.Code("{0}[{1}].NpgsqlDbType = {2};", parameters, i, DbType);
 }
예제 #37
0
        private void IdentityUserContextBase(ModelBuilder builder)
        {
            StoreOptions storeOptions = this.GetService <IDbContextOptions>()
                                        .Extensions.OfType <CoreOptionsExtension>()
                                        .FirstOrDefault()?.ApplicationServiceProvider
                                        ?.GetService <IOptions <IdentityOptions> >()
                                        ?.Value?.Stores;

            var maxKeyLength                = storeOptions?.MaxLengthForKeys ?? 0;
            var encryptPersonalData         = storeOptions?.ProtectPersonalData ?? false;
            PersonalDataConverter converter = null;

            builder.Entity <MultiTenantUserIdentity>(b =>
            {
                b.HasKey(u => u.Id);
                //b.HasIndex(u => u.NormalizedUserName).HasName("UserNameIndex").IsUnique();
                b.HasIndex(u => u.NormalizedUserName).HasName("UserNameIndex");
                b.HasIndex(u => u.NormalizedEmail).HasName("EmailIndex");
                //b.ToTable("AspNetUsers");
                b.Property(u => u.ConcurrencyStamp).IsConcurrencyToken();

                b.Property(u => u.UserName).HasMaxLength(256);
                b.Property(u => u.NormalizedUserName).HasMaxLength(256);
                b.Property(u => u.Email).HasMaxLength(256);
                b.Property(u => u.NormalizedEmail).HasMaxLength(256);

                if (encryptPersonalData)
                {
                    converter             = new PersonalDataConverter(this.GetService <IPersonalDataProtector>());
                    var personalDataProps = typeof(MultiTenantUserIdentity).GetProperties().Where(
                        prop => Attribute.IsDefined(prop, typeof(ProtectedPersonalDataAttribute)));
                    foreach (var p in personalDataProps)
                    {
                        if (p.PropertyType != typeof(string))
                        {
                            throw new InvalidOperationException("Can only protect strings");
                        }
                        b.Property(typeof(string), p.Name).HasConversion(converter);
                    }
                }

                b.HasMany <UserIdentityUserClaim>().WithOne().HasForeignKey(uc => uc.UserId).IsRequired();
                b.HasMany <UserIdentityUserLogin>().WithOne().HasForeignKey(ul => ul.UserId).IsRequired();
                b.HasMany <UserIdentityUserToken>().WithOne().HasForeignKey(ut => ut.UserId).IsRequired();
            });

            builder.Entity <UserIdentityUserClaim>(b =>
            {
                b.HasKey(uc => uc.Id);
                //b.ToTable("AspNetUserClaims");
            });

            builder.Entity <UserIdentityUserLogin>(b =>
            {
                b.HasKey(l => new { l.LoginProvider, l.ProviderKey });

                if (maxKeyLength > 0)
                {
                    b.Property(l => l.LoginProvider).HasMaxLength(maxKeyLength);
                    b.Property(l => l.ProviderKey).HasMaxLength(maxKeyLength);
                }

                //b.ToTable("AspNetUserLogins");
            });

            builder.Entity <UserIdentityUserToken>(b =>
            {
                b.HasKey(t => new { t.UserId, t.LoginProvider, t.Name });

                if (maxKeyLength > 0)
                {
                    b.Property(t => t.LoginProvider).HasMaxLength(maxKeyLength);
                    b.Property(t => t.Name).HasMaxLength(maxKeyLength);
                }

                if (encryptPersonalData)
                {
                    var tokenProps = typeof(UserIdentityUserToken).GetProperties()
                                     .Where(prop => Attribute.IsDefined(prop, typeof(ProtectedPersonalDataAttribute)));
                    foreach (var p in tokenProps)
                    {
                        if (p.PropertyType != typeof(string))
                        {
                            throw new InvalidOperationException("Can only protect strings");
                        }
                        b.Property(typeof(string), p.Name).HasConversion(converter);
                    }
                }

                //b.ToTable("AspNetUserTokens");
            });
        }
예제 #38
0
 public bool IsActive(StoreOptions options) => _events.Any() || _aggregates.Any();
예제 #39
0
 public bool IsActive(StoreOptions options) => _events.Any() || _aggregates.Value.Enumerate().Any();
예제 #40
0
 internal static void ConfigureOrders(this StoreOptions options)
 {
     // Snapshots
     options.Projections.SelfAggregate <Order>();
 }
예제 #41
0
 public TransformFunction(StoreOptions options, string name, string body)
     : base(new DbObjectName(options.DatabaseSchemaName, "mt_transform_" + name.Replace(".", "_")))
 {
     Name = name;
     Body = body;
 }
예제 #42
0
 public override void GenerateCodeToSetDbParameterValue(GeneratedMethod method, GeneratedType type, int i, Argument parameters,
                                                        DocumentMapping mapping, StoreOptions options)
 {
     method.Frames.Code($"setStringParameter({parameters.Usage}[{i}], {{0}}.{nameof(IMartenSession.CorrelationId)});", Use.Type <IMartenSession>());
 }
예제 #43
0
 public CompiledQuerySourceBuilder(CompiledQueryPlan plan, StoreOptions storeOptions)
 {
     _plan         = plan;
     _storeOptions = storeOptions;
     _typeName     = _plan.QueryType.Name + "CompiledQuerySource";
 }
예제 #44
0
 public bool IsActive(StoreOptions options)
 {
     return(true);
 }
예제 #45
0
 public static void ConfigureMarten(StoreOptions options)
 {
     options.Events.Projections.SelfAggregate <Meeting>();
     options.Events.Projections.Add(new MeetingViewProjection());
 }
예제 #46
0
 private void SetupEventStore(StoreOptions options)
 {
     options.Events.InlineProjections.AggregateStreamsWith <Issue>();
     options.Events.InlineProjections.Add(new IssueProjection());
 }
예제 #47
0
        public void DefaultAutoCreateShouldBeCreateOrUpdate()
        {
            var settings = new StoreOptions();

            Assert.Equal(AutoCreate.CreateOrUpdate, settings.AutoCreateSchemaObjects);
        }
예제 #48
0
 public MartenExpressionParser(ISerializer serializer, StoreOptions options)
 {
     _serializer = serializer;
     _options    = options;
 }
        internal void Compile(StoreOptions options)
        {
            var rules = options.CreateGenerationRules();

            Compile(options, rules);
        }
예제 #50
0
 protected FeatureSchemaBase(string identifier, StoreOptions options)
 {
     Identifier = identifier;
     Options    = options;
 }
예제 #51
0
 public FakeStorage(StoreOptions options) : base("fake", options)
 {
 }
예제 #52
0
 internal static void ConfigureOrders(this StoreOptions options)
 {
 }
예제 #53
0
 public MartenAuthRepositoryConfig(StoreOptions storeOptions)
 {
     _storeOptions = storeOptions;
 }
예제 #54
0
        public static int Execute(StoreOptions options, string[] args)
        {
            var executor = For(options, f => { });

            return(executor.Execute(args));
        }
예제 #55
0
 public DocumentCleaner(StoreOptions options, ITenant tenant)
 {
     _options = options;
     _tenant  = tenant;
 }
예제 #56
0
 public SequenceFactory(StoreOptions options, ITenant tenant)
 {
     _options = options;
     _tenant  = tenant;
 }
예제 #57
0
 internal ProjectionCollection(StoreOptions options)
 {
     _options = options;
 }
예제 #58
0
 public SequenceFactory(IConnectionFactory factory, StoreOptions options)
 {
     _factory = factory;
     _options = options;
 }
예제 #59
0
 internal static void ConfigurePayments(this StoreOptions options)
 {
     // Snapshots
     options.Events.InlineProjections.AggregateStreamsWith <Payment>();
 }
예제 #60
0
 public ProviderGraph(StoreOptions options)
 {
     _options = options;
 }