Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/brave-mangos-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@hive/migrations': minor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'@hive/migrations': minor
'hive': minor

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dangerous 🤣

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There it is again !!!!!!! 🤣

---

Add configurable data retention TTL for self-hosted Hive instances. Self-hosted users can now configure retention periods via environment variables instead of hardcoded values.

New environment variables:
- `CLICKHOUSE_TTL_TABLES` - Retention for ClickHouse mergetree tables (Default: 1 YEAR)
- `CLICKHOUSE_TTL_DAILY_MV_TABLES` - Retention for daily materialized view tables (Default: 1 YEAR)
- `CLICKHOUSE_TTL_HOURLY_MV_TABLES` - Retention for hourly materialized view tables (Default: 30 DAYS)
- `CLICKHOUSE_TTL_MINUTELY_MV_TABLES` - Retention for minutely materialized view tables (Default: 24 HOURS)

Supports both numeric days (e.g., `365`) and ClickHouse interval syntax (e.g., `"1 YEAR"`, `"30 DAY"`, `"24 HOUR"`).

The retention update runs automatically if any retention environment variable is set.
4 changes: 4 additions & 0 deletions docker/docker-compose.community.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ services:
CLICKHOUSE_PORT: '8123'
CLICKHOUSE_USERNAME: '${CLICKHOUSE_USER}'
CLICKHOUSE_PASSWORD: '${CLICKHOUSE_PASSWORD}'
CLICKHOUSE_TTL_TABLES: '${CLICKHOUSE_TTL_TABLES:-}'
CLICKHOUSE_TTL_DAILY_MV_TABLES: '${CLICKHOUSE_TTL_DAILY_MV_TABLES:-}'
CLICKHOUSE_TTL_HOURLY_MV_TABLES: '${CLICKHOUSE_TTL_HOURLY_MV_TABLES:-}'
CLICKHOUSE_TTL_MINUTELY_MV_TABLES: '${CLICKHOUSE_TTL_MINUTELY_MV_TABLES:-}'
TS_NODE_TRANSPILE_ONLY: 'true'
LOG_LEVEL: '${LOG_LEVEL:-debug}'

Expand Down
4 changes: 4 additions & 0 deletions packages/migrations/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ CLICKHOUSE_HOST="localhost"
CLICKHOUSE_PORT="8123"
CLICKHOUSE_USERNAME="test"
CLICKHOUSE_PASSWORD="test"
# CLICKHOUSE_TTL_TABLES="1 YEAR"
# CLICKHOUSE_TTL_DAILY_MV_TABLES="30 DAYS"
# CLICKHOUSE_TTL_HOURLY_MV_TABLES="7 DAYS"
# CLICKHOUSE_TTL_MINUTELY_MV_TABLES="1 DAY"

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
Expand Down
22 changes: 22 additions & 0 deletions packages/migrations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { migrateClickHouse } from './clickhouse';
import { createConnectionString } from './connection-string';
import { env } from './environment';
import { runPGMigrations } from './run-pg-migrations';
import { updateRetention } from './scripts/update-retention';

const slonik = await createPool(createConnectionString(env.postgres), {
// 10 minute timeout per statement
Expand Down Expand Up @@ -38,6 +39,27 @@ try {
env.clickhouse,
);
}

// Automatically apply retention if any retention setting is configured
// eslint-disable-next-line no-process-env
if (
// eslint-disable-next-line no-process-env
process.env.CLICKHOUSE_TTL_TABLES ||
// eslint-disable-next-line no-process-env
process.env.CLICKHOUSE_TTL_DAILY_MV_TABLES ||
// eslint-disable-next-line no-process-env
process.env.CLICKHOUSE_TTL_HOURLY_MV_TABLES ||
// eslint-disable-next-line no-process-env
process.env.CLICKHOUSE_TTL_MINUTELY_MV_TABLES
) {
console.log('Applying clickhouse retention settings...');
try {
await updateRetention();
} catch (error) {
console.error('Failed to update retention (non-fatal):', error);
}
}

process.exit(0);
} catch (error) {
console.error(error);
Expand Down
Loading
Loading