From 6403c77e066f0f9c2efde79943c4b4dfd46cd95a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Wed, 10 Dec 2025 21:50:08 +0100 Subject: [PATCH] fix: set end date on migrations --- packages/db/code-migrations/8-order-keys.ts | 12 ++++++++++++ packages/db/code-migrations/migrate.ts | 2 ++ 2 files changed, 14 insertions(+) diff --git a/packages/db/code-migrations/8-order-keys.ts b/packages/db/code-migrations/8-order-keys.ts index 4fe699dd..640edd8e 100644 --- a/packages/db/code-migrations/8-order-keys.ts +++ b/packages/db/code-migrations/8-order-keys.ts @@ -142,12 +142,18 @@ export async function up() { const firstEventDate = new Date(firstEventDateJson[0]?.created_at ?? ''); if (firstEventDate) { // Step 2: Copy data from old tables to new tables (partitioned by month for efficiency) + // Set endDate to first of next month to ensure we capture all data in the current month + const endDate = new Date(); + endDate.setMonth(endDate.getMonth() + 1); + endDate.setDate(1); + sqls.push( ...moveDataBetweenTables({ from: 'events', to: 'events_new_20251123', batch: { startDate: firstEventDate, + endDate: endDate, column: 'toDate(created_at)', interval: 'month', transform: (date: Date) => { @@ -170,6 +176,11 @@ export async function up() { const firstSessionDate = new Date(firstSessionDateJson[0]?.created_at ?? ''); if (firstSessionDate) { + // Set endDate to first of next month to ensure we capture all data in the current month + const endDate = new Date(); + endDate.setMonth(endDate.getMonth() + 1); + endDate.setDate(1); + sqls.push( ...moveDataBetweenTables({ from: 'sessions', @@ -215,6 +226,7 @@ export async function up() { ], batch: { startDate: firstSessionDate, + endDate: endDate, column: 'toDate(created_at)', interval: 'month', transform: (date: Date) => { diff --git a/packages/db/code-migrations/migrate.ts b/packages/db/code-migrations/migrate.ts index 1b10b37d..3f4a5eac 100644 --- a/packages/db/code-migrations/migrate.ts +++ b/packages/db/code-migrations/migrate.ts @@ -59,6 +59,8 @@ async function migrate() { if (!getIsDry()) { printBoxMessage('🕒 Migrations starts in 10 seconds', []); await new Promise((resolve) => setTimeout(resolve, 10000)); + } else { + printBoxMessage('🕒 Migrations starts now (dry run)', []); } }