denis-ivanov / EntityFrameworkCore.ClickHouse

ClickHouse provider for Entity Framework Core.
https://clickhouse.tech/
23 stars 5 forks source link

EF migration history table is created with default engine StripeLog which is not supported by Clickhouse Cloud #61

Closed ehsanYazdani closed 2 weeks ago

ehsanYazdani commented 1 month ago

Please correct me if I'm wrong but from what I can see in the code base the default engine is StripeLog unless explicitly annotated on an entity type. For the history log table, however, (again to my understanding) there is no way of providing an annotation and hence the table is created with StripeLog engine. Unfortunately Clickhouse Cloud does not support StripeLog as it runs the service on multiple (distributed) instances.

I'm curious to hear why StripeLog is default in this lib whereas MergeTree is default in Clickhouse? In any case, is there anyway the engine for the history table can be customized?

AniMeIIIkA commented 4 weeks ago

Workaround method what i use

public class CustomClickHouseHistoryRepository : ClickHouseHistoryRepository {
    public CustomClickHouseHistoryRepository(HistoryRepositoryDependencies dependencies) : base(dependencies) {
    }

    protected override void ConfigureTable(EntityTypeBuilder<HistoryRow> history) {
        history.Property<string>(h => h.MigrationId).HasMaxLength(150);
        history.Property<string>(h => h.ProductVersion).HasMaxLength(32).IsRequired(true);
        history.ToTable("__EFMigrationsHistory", table => table
           .HasMergeTreeEngine()
           .WithPrimaryKey("MigrationId"));
    }
}

Into ClickHouseDbContext

protected override void OnConfiguring(DbContextOptionsBuilder options) {
    options.ReplaceService<IHistoryRepository, CustomClickHouseHistoryRepository>();
}
ehsanYazdani commented 4 weeks ago

Thanks for the workaround @AniMeIIIkA. It works great. However, I'm still curious to hear why @denis-ivanov has chosen stripelog was chosen as the default engine.

denis-ivanov commented 2 weeks ago

@ehsanYazdani, I do not use ClickHouse cloud. StripeLog was the easiest way to start writing functional tests.

@AniMeIIIkA, thanks for workground. I changed default behavior.