@mastra/clickhouse 1.15.1 → 1.15.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -165,17 +165,6 @@ function rewriteEngineClauses(sql, replication) {
165
165
  function applyReplicationToDDL(sql, replication) {
166
166
  return addOnClusterToDDL(replication ? rewriteEngineClauses(sql, replication) : sql, replication);
167
167
  }
168
- function buildLocalTableReplicationError(tables) {
169
- const tableList = tables.map((table) => ` - ${table.name} (${table.engine})`).join("\n");
170
- return new MastraError({
171
- id: createStorageErrorId("CLICKHOUSE", "REPLICATION", "LOCAL_TABLES_UNSUPPORTED"),
172
- domain: ErrorDomain.STORAGE,
173
- category: ErrorCategory.USER,
174
- text: `ClickHouse replication is enabled, but existing Mastra tables use non-replicated local engines.
175
- Mastra will not automatically convert existing local tables to replicated tables.
176
- Please migrate or recreate these tables manually before enabling replication:\n${tableList}`
177
- });
178
- }
179
168
  //#endregion
180
169
  //#region src/storage/db/utils.ts
181
170
  const TABLE_ENGINES = {
@@ -350,12 +339,12 @@ var ClickhouseDB = class extends MastraBase {
350
339
  }
351
340
  async assertExistingTableCompatibleWithReplication(tableName) {
352
341
  if (!isReplicationConfigured(this.replication)) return;
353
- const localTables = (await (await this.client.query({
342
+ const localTable = (await (await this.client.query({
354
343
  query: `SELECT name, engine FROM system.tables WHERE database = currentDatabase() AND name = {tableName:String}`,
355
344
  query_params: { tableName },
356
345
  format: "JSONEachRow"
357
- })).json()).filter((row) => row.engine && !isReplicatedOrSharedEngine(row.engine));
358
- if (localTables.length > 0) throw buildLocalTableReplicationError(localTables);
346
+ })).json()).find((row) => row.engine && !isReplicatedOrSharedEngine(row.engine));
347
+ if (localTable) this.logger.warn(`ClickHouse replication is enabled, but pre-existing table '${localTable.name}' uses local engine '${localTable.engine}'. CREATE TABLE IF NOT EXISTS will leave the existing table untouched.`);
359
348
  }
360
349
  /**
361
350
  * Gets the sorting key (ORDER BY columns) for a table.
@@ -7031,17 +7020,14 @@ async function filterAppliedRetention(client, entries) {
7031
7020
  * Silently returns if `system.tables` can't be queried — the rest of init
7032
7021
  * will still run and leave any existing tables untouched.
7033
7022
  */
7034
- async function assertExistingTablesCompatibleWithReplication(client, replication) {
7023
+ async function assertExistingTablesCompatibleWithReplication(client, replication, logger) {
7035
7024
  if (!isReplicationConfigured(replication)) return;
7036
7025
  const localTable = (await (await client.query({
7037
7026
  query: `SELECT name, engine FROM system.tables WHERE database = currentDatabase() AND name IN ({tables:Array(String)})`,
7038
7027
  query_params: { tables: [...ALL_TABLE_NAMES] },
7039
7028
  format: "JSONEachRow"
7040
7029
  })).json()).find((row) => !isReplicatedOrSharedEngine(row.engine));
7041
- if (localTable) throw buildLocalTableReplicationError([{
7042
- name: localTable.name,
7043
- engine: localTable.engine
7044
- }]);
7030
+ if (localTable) logger.warn(`ClickHouse replication is enabled, but pre-existing observability table '${localTable.name}' uses local engine '${localTable.engine}'. CREATE TABLE IF NOT EXISTS will leave existing tables untouched.`);
7045
7031
  }
7046
7032
  async function reconcileDiscoveryTables(client, replication) {
7047
7033
  let engines;
@@ -7160,7 +7146,7 @@ var ObservabilityStorageClickhouseVNext = class extends ObservabilityStorage {
7160
7146
  if ((await checkLegacySpanMigrationStatus(this.#client)).needsMigration) this.logger?.warn?.("Legacy span table 'mastra_ai_spans' detected. Run 'npx mastra migrate' to migrate historical spans to the v-next schema.");
7161
7147
  } catch {}
7162
7148
  try {
7163
- await assertExistingTablesCompatibleWithReplication(this.#client, this.#replication);
7149
+ await assertExistingTablesCompatibleWithReplication(this.#client, this.#replication, this.logger);
7164
7150
  const existingStrategy = await detectExistingDeltaCursorStrategy(this.#client);
7165
7151
  if (existingStrategy === "mixed") {
7166
7152
  this.#deltaCursorStrategy = null;
@@ -7244,8 +7230,12 @@ var ObservabilityStorageClickhouseVNext = class extends ObservabilityStorage {
7244
7230
  };
7245
7231
  }
7246
7232
  getFeatures() {
7247
- if (!deltaPollingSupported(this.#deltaCursorStrategy)) return;
7248
- return ["delta-polling"];
7233
+ if (!deltaPollingSupported(this.#deltaCursorStrategy)) return ["metrics", "logs"];
7234
+ return [
7235
+ "metrics",
7236
+ "logs",
7237
+ "delta-polling"
7238
+ ];
7249
7239
  }
7250
7240
  async createSpan(args) {
7251
7241
  try {