Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: add cluster support for ClickHouse database creation (#1742)

Danny Xu159a6bb42903
diff --git a/api/issue.go b/api/issue.go
index d0f4c24e98..907c242650 100644
--- a/api/issue.go
+++ b/api/issue.go
@@ -127,6 +127,8 @@ type CreateDatabaseContext struct {
CharacterSet string `json:"characterSet"`
// Collation is the collation of the database.
Collation string `json:"collation"`
+ // Cluster is the cluster of the database. This is only applicable to ClickHouse for "ON CLUSTER <<cluster>>".
+ Cluster string `json:"cluster"`
// Owner is the owner of the database. This is only applicable to Postgres for "WITH OWNER <<owner>>".
Owner string `json:"owner"`
// BackupID is the ID of the backup.
diff --git a/frontend/src/components/CreateDatabasePrepForm.vue b/frontend/src/components/CreateDatabasePrepForm.vue
index d1389cc86a..439e7501c9 100644
--- a/frontend/src/components/CreateDatabasePrepForm.vue
+++ b/frontend/src/components/CreateDatabasePrepForm.vue
@@ -81,6 +81,24 @@
/>
</div>
+ <div
+ v-if="selectedInstance.engine == 'CLICKHOUSE'"
+ class="col-span-2 col-start-2 w-64"
+ >
+ <label for="name" class="textlabel">
+ {{ $t("create-db.cluster") }}
+ <span class="text-red-600">*</span>
+ </label>
+ <input
+ id="name"
+ v-model="state.cluster"
+ required
+ name="cluster"
+ type="text"
+ class="textfield mt-1 w-full"
+ />
+ </div>
+
<!-- Providing more dropdowns for required labels as if they are normal required props of DB -->
<DatabaseLabelForm
v-if="isTenantProject"
@@ -277,6 +295,7 @@ interface LocalState {
databaseOwnerName: string;
characterSet: string;
collation: string;
+ cluster: string;
assigneeId?: PrincipalId;
showFeatureModal: boolean;
}
@@ -345,6 +364,7 @@ export default defineComponent({
labelList: [],
characterSet: "",
collation: "",
+ cluster: "",
assigneeId: showAssigneeSelect.value ? undefined : SYSTEM_BOT_ID,
showFeatureModal: false,
});
@@ -494,6 +514,7 @@ export default defineComponent({
collation:
state.collation ||
defaultCollation(selectedInstance.value.engine),
+ cluster: state.cluster,
backupId: props.backup.id,
backupName: props.backup.name,
},
@@ -520,6 +541,7 @@ export default defineComponent({
collation:
state.collation ||
defaultCollation(selectedInstance.value.engine),
+ cluster: state.cluster,
},
payload: {},
};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index e8fb525f19..86e24b175d 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -516,6 +516,7 @@
"create-db": {
"new-database-name": "New database name",
"database-owner-name": "Database owner name",
+ "cluster": "Cluster",
"reserved-db-error": "{databaseName} is a reserved name",
"generated-database-name": "Generated database name",
"db-name-generated-by-template": "Generated by template \"{template}\"",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 570a89e2fe..b8c756745e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -517,6 +517,7 @@
"create-db": {
"new-database-name": "新数据库名称",
"database-owner-name": "数据库所有者",
+ "cluster": "集群",
"reserved-db-error": "{databaseName} 是一个预留名称",
"generated-database-name": "生成的数据库名称",
"db-name-generated-by-template": "依据模板 \"{template}\" 生成",
diff --git a/frontend/src/types/issue.ts b/frontend/src/types/issue.ts
index 83c6ca186e..925daae95c 100644
--- a/frontend/src/types/issue.ts
+++ b/frontend/src/types/issue.ts
@@ -37,6 +37,7 @@ export type CreateDatabaseContext = {
owner: string;
characterSet: string;
collation: string;
+ cluster: string;
backupId: BackupId;
backupName: string;
labels?: string; // JSON encoded
diff --git a/server/issue.go b/server/issue.go
index 388987a8a4..e631747641 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -1034,7 +1034,11 @@ func getDatabaseNameAndStatement(dbType db.Type, createDatabaseContext api.Creat
stmt = fmt.Sprintf("%s\n\\connect \"%s\";\n%s", stmt, databaseName, schema)
}
case db.ClickHouse:
- stmt = fmt.Sprintf("CREATE DATABASE `%s`;", databaseName)
+ clusterPart := ""
+ if createDatabaseContext.Cluster != "" {
+ clusterPart = fmt.Sprintf(" ON CLUSTER `%s`", createDatabaseContext.Cluster)
+ }
+ stmt = fmt.Sprintf("CREATE DATABASE `%s`%s;", databaseName, clusterPart)
if schema != "" {
stmt = fmt.Sprintf("%s\nUSE `%s`;\n%s", stmt, databaseName, schema)
}