ClickHouse / ClickHouse/ClickHouse.EntityFrameworkCore
Feature Request: Add Support for EFCore Schemas by Treating Them as Databases
- 主要语言
- C#
- 星标
- 23
- 派生
- 7
- 平均合并
- 14 天 3 小时
- 30 天内合并 PR
- 1
描述
### Feature Request
EFCore Entity Schemas can be treated like Clickhouse Databases to make EFCore output valid migrations.
In this feature request I propose a change to how Schemas are handled. I will be submitting a pull request along with my feature request.
### Current behavior
Defining an EFCore Entity Configuration such that:
```
e.ToTable("my_table", "my_schema", table =>
{
table.HasMergeTreeEngine()
.WithOrderBy("Timestamp")
.WithPartitionBy("toYear(Timestamp)");
});
e.Property(x => x.Timestamp)
.HasColumnType("Date")
.HasColumnName("Timestamp");
e.Property(x => x.MyString)
.HasColumnType("String")
.HasColumnName("MyString");
e.HasNoKey();
```
and using that entity configuration in an EFCore migration produces the following migration code:
```
migrationBuilder.EnsureSchema(
name: "my_schema");
migrationBuilder.CreateTable(
name: "my_table",
schema: "my_schema",
columns: table => new
{
Timestamp = table.Column(type: "Date32", nullable: false)
},
constraints: table =>
{
})
.Annotation("ClickHouse:Engine", "MergeTree")
.Annotation("ClickHouse:OrderBy", new[] { "Timestamp" })
.Annotation("ClickHouse:PartitionBy", new[] { "toYear(Timestamp)" });
```
Which fails on the ensure schema operation, saying schemas are not supported. This makes it difficult define database structure in EFCore.
### Expected behavior
```
// C# EFCore Migration
migrationBuilder.EnsureSchema(
name: "pre_aggregates");
migrationBuilder.CreateTable(
name: "my_table",
schema: "my_schema",
columns: table => new
{
Timestamp = table.Column(type: "Date32", nullable: false)
MyString = table.Column(type: "String", nullable: false),
},
constraints: table =>
{
})
.Annotation("ClickHouse:Engine", "MergeTree")
.Annotation("ClickHouse:OrderBy", new[] { "Timestamp" })
.Annotation("ClickHouse:PartitionBy", new[] { "toYear(Timestamp)" });
```
// Should translate to:
```
CREATE DATABASE my_schema;
CREATE TABLE `my_schema`.`my_table` (
`Timestamp` Date32,
`MyString` String
)
ENGINE = MergeTree()
ORDER BY (`Timestamp`)
PARTITION BY toYear(Timestamp);
```
贡献指南
这个仓库没有索引到贡献指南
调研方向
首先跟踪 provider 对 EnsureSchema 和 CreateTable 的 EFCore migration 处理,并以 issue 中的 migration 和 SQL 示例作为预期行为。确认带 schema 限定的表和 ClickHouse engine annotation 是如何转换的。当 EnsureSchema 生成 CREATE DATABASE,且表 migration 生成有效的带 schema 限定的 ClickHouse SQL 时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp, sql
- 领域
- databases
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100