fix: minor things before merging new order keys

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-12-02 19:03:34 +01:00
parent 7c387bb6ae
commit 25e3a84bf6
7 changed files with 42 additions and 48 deletions

View File

@@ -9,25 +9,6 @@ import {
} from '../src/clickhouse/migration';
import { getIsCluster } from './helpers';
/**
* Migration to update ORDER BY keys for events and sessions tables.
*
* Changes:
* - Events: Remove profile_id from ORDER BY, add created_at for better ordering
* Old: ['project_id', 'toDate(created_at)', 'profile_id', 'name']
* New: ['project_id', 'toDate(created_at)', 'created_at', 'name']
*
* - Sessions: Remove profile_id from ORDER BY, reorder to match query patterns
* Old: ['project_id', 'id', 'toDate(created_at)', 'profile_id']
* New: ['project_id', 'toDate(created_at)', 'created_at', 'id']
*
* Rationale:
* - project_id: Always filtered first (100% of queries)
* - toDate(created_at): Almost always filtered (95%+ of queries), good for partitioning
* - created_at: Helps with ordering within same day, matches ORDER BY patterns in queries
* - name (events): Frequently filtered (screen_view, session_start, etc.), good selectivity
* - id (sessions): Used for ordering and uniqueness in session queries
*/
export async function up() {
const isClustered = getIsCluster();

View File

@@ -30,3 +30,7 @@ export function getIsSelfHosting() {
export function getIsDry() {
return process.argv.includes('--dry');
}
export function getShouldIgnoreRecord() {
return process.argv.includes('--no-record');
}

View File

@@ -10,6 +10,7 @@ import {
getIsCluster,
getIsDry,
getIsSelfHosting,
getShouldIgnoreRecord,
printBoxMessage,
} from './helpers';
@@ -55,8 +56,8 @@ async function migrate() {
]);
if (!getIsSelfHosting()) {
printBoxMessage('🕒 Migrations starts in 10 seconds', []);
if (!getIsDry()) {
printBoxMessage('🕒 Migrations starts in 10 seconds', []);
await new Promise((resolve) => setTimeout(resolve, 10000));
}
}
@@ -83,7 +84,7 @@ async function runMigration(migrationsDir: string, file: string) {
try {
const migration = await import(path.join(migrationsDir, file));
await migration.up();
if (!getIsDry()) {
if (!getIsDry() && !getShouldIgnoreRecord()) {
await db.codeMigration.upsert({
where: {
name: file,