コード例 #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
ファイル: MartenRegistryTests.cs プロジェクト: nieve/marten
        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
ファイル: SequenceFactory.cs プロジェクト: JasperFx/marten
 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
ファイル: UpdateBatch.cs プロジェクト: Xamarui/marten
        public UpdateBatch(StoreOptions options, ISerializer serializer, IManagedConnection connection)
        {
            _options = options;
            _serializer = serializer;

            _commands.Push(new BatchCommand(serializer));
            Connection = connection;
        }
コード例 #8
0
ファイル: UpdateBatch.cs プロジェクト: kiliman/marten
        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
ファイル: SchemaBuilder.cs プロジェクト: danielmarbach/marten
        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
ファイル: FunctionDiff.cs プロジェクト: danielmarbach/marten
        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
ファイル: TransformFunction.cs プロジェクト: JasperFx/marten
        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
ファイル: SchemaDiff.cs プロジェクト: danielmarbach/marten
        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));
        }
コード例 #14
0
        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
ファイル: HiLoSequence.cs プロジェクト: JasperFx/marten
        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
ファイル: UpdateBatch.cs プロジェクト: danielmarbach/marten
        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");
        }
コード例 #18
0
        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");
        }
コード例 #21
0
        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);
                }
            }
        }
コード例 #22
0
        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\";");

        }
コード例 #26
0
        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;
        }
コード例 #29
0
        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
ファイル: TestingDocumentStore.cs プロジェクト: nieve/marten
        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
ファイル: TransformSchema.cs プロジェクト: tonykaralis/marten
 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
ファイル: DefaultTenancy.cs プロジェクト: MxLabs/marten
 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
ファイル: EventGraph.cs プロジェクト: psmith6/marten
 public bool IsActive(StoreOptions options) => _events.Any() || _aggregates.Any();
コード例 #39
0
ファイル: EventGraph.cs プロジェクト: kasparurban/marten
 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
ファイル: TransformSchema.cs プロジェクト: tonykaralis/marten
 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
ファイル: Module.cs プロジェクト: gitter-badger/GoldenEye
 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;
 }
コード例 #49
0
        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
ファイル: SequenceFactory.cs プロジェクト: jessetechie/marten
 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;
 }