public EventStoreAdmin(IDocumentSchema schema, IConnectionFactory connectionFactory, StoreOptions options, ISerializer serializer) { _schema = schema; _connectionFactory = connectionFactory; _options = options; _serializer = serializer; }
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};"); } }
public MartenRegistryTests() { var storeOptions = new StoreOptions(); storeOptions.Schema.Include<TestRegistry>(); theSchema = new DocumentSchema(storeOptions, new ConnectionSource(), new NulloMartenLogger()); }
public void event_name_for_event_type() { var options = new StoreOptions(); var mapping = new EventMapping<MembersJoined>(new EventGraph(options)); mapping.EventTypeName.ShouldBe("members_joined"); }
public SequenceFactory(IDocumentSchema schema, IConnectionFactory factory, StoreOptions options, IMartenLogger logger) { _schema = schema; _factory = factory; _options = options; _logger = logger; }
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; }
public UpdateBatch(StoreOptions options, ISerializer serializer, IManagedConnection connection) { _options = options; _serializer = serializer; _commands.Push(new BatchCommand(serializer)); Connection = connection; }
public UpdateBatch(StoreOptions options, ISerializer serializer, ICommandRunner runner) { _options = options; _serializer = serializer; _runner = runner; _commands.Push(new BatchCommand(serializer)); }
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; }
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); }
private void writeOwnership(StoreOptions options, SchemaPatch patch) { if (options.OwnerName.IsEmpty()) return; var ownership = Expected.ToOwnershipCommand(options.OwnerName); patch.Updates.Apply(this, ownership); }
public TransformFunction(StoreOptions options, string name, string body) { _options = options; Name = name; Body = body; Function = new FunctionName(_options.DatabaseSchemaName, $"{Prefix}{Name.ToLower().Replace(".", "_")}"); }
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"); }
public HiloSequence(IConnectionFactory factory, StoreOptions options, string entityName, HiloSettings settings) { _factory = factory; _options = options; _entityName = entityName; CurrentHi = -1; CurrentLo = 1; MaxLo = settings.MaxLo; }
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; }
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"); }
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()); }
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; "); }
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"); }
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; }
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(); } }
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"); }
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}\";"); } }
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; }
public TransformSchema(StoreOptions options) { _options = options; }
internal static void ConfigurePayments(this StoreOptions options) { // Snapshots options.Events.Projections.SelfAggregate <Payment>(); }
public bool IsActive(StoreOptions options) => _events.Any() || Projections.Any();
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>()); }
public bool IsActive(StoreOptions options) => true;
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); }
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"); }); }
public bool IsActive(StoreOptions options) => _events.Any() || _aggregates.Any();
public bool IsActive(StoreOptions options) => _events.Any() || _aggregates.Value.Enumerate().Any();
internal static void ConfigureOrders(this StoreOptions options) { // Snapshots options.Projections.SelfAggregate <Order>(); }
public TransformFunction(StoreOptions options, string name, string body) : base(new DbObjectName(options.DatabaseSchemaName, "mt_transform_" + name.Replace(".", "_"))) { Name = name; Body = body; }
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>()); }
public CompiledQuerySourceBuilder(CompiledQueryPlan plan, StoreOptions storeOptions) { _plan = plan; _storeOptions = storeOptions; _typeName = _plan.QueryType.Name + "CompiledQuerySource"; }
public bool IsActive(StoreOptions options) { return(true); }
public static void ConfigureMarten(StoreOptions options) { options.Events.Projections.SelfAggregate <Meeting>(); options.Events.Projections.Add(new MeetingViewProjection()); }
private void SetupEventStore(StoreOptions options) { options.Events.InlineProjections.AggregateStreamsWith <Issue>(); options.Events.InlineProjections.Add(new IssueProjection()); }
public void DefaultAutoCreateShouldBeCreateOrUpdate() { var settings = new StoreOptions(); Assert.Equal(AutoCreate.CreateOrUpdate, settings.AutoCreateSchemaObjects); }
public MartenExpressionParser(ISerializer serializer, StoreOptions options) { _serializer = serializer; _options = options; }
internal void Compile(StoreOptions options) { var rules = options.CreateGenerationRules(); Compile(options, rules); }
protected FeatureSchemaBase(string identifier, StoreOptions options) { Identifier = identifier; Options = options; }
public FakeStorage(StoreOptions options) : base("fake", options) { }
internal static void ConfigureOrders(this StoreOptions options) { }
public MartenAuthRepositoryConfig(StoreOptions storeOptions) { _storeOptions = storeOptions; }
public static int Execute(StoreOptions options, string[] args) { var executor = For(options, f => { }); return(executor.Execute(args)); }
public DocumentCleaner(StoreOptions options, ITenant tenant) { _options = options; _tenant = tenant; }
public SequenceFactory(StoreOptions options, ITenant tenant) { _options = options; _tenant = tenant; }
internal ProjectionCollection(StoreOptions options) { _options = options; }
public SequenceFactory(IConnectionFactory factory, StoreOptions options) { _factory = factory; _options = options; }
internal static void ConfigurePayments(this StoreOptions options) { // Snapshots options.Events.InlineProjections.AggregateStreamsWith <Payment>(); }
public ProviderGraph(StoreOptions options) { _options = options; }