Skip to content

Commit 6403c77

Browse files
committed
fix: set end date on migrations
1 parent 396f509 commit 6403c77

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/db/code-migrations/8-order-keys.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,18 @@ export async function up() {
142142
const firstEventDate = new Date(firstEventDateJson[0]?.created_at ?? '');
143143
if (firstEventDate) {
144144
// Step 2: Copy data from old tables to new tables (partitioned by month for efficiency)
145+
// Set endDate to first of next month to ensure we capture all data in the current month
146+
const endDate = new Date();
147+
endDate.setMonth(endDate.getMonth() + 1);
148+
endDate.setDate(1);
149+
145150
sqls.push(
146151
...moveDataBetweenTables({
147152
from: 'events',
148153
to: 'events_new_20251123',
149154
batch: {
150155
startDate: firstEventDate,
156+
endDate: endDate,
151157
column: 'toDate(created_at)',
152158
interval: 'month',
153159
transform: (date: Date) => {
@@ -170,6 +176,11 @@ export async function up() {
170176

171177
const firstSessionDate = new Date(firstSessionDateJson[0]?.created_at ?? '');
172178
if (firstSessionDate) {
179+
// Set endDate to first of next month to ensure we capture all data in the current month
180+
const endDate = new Date();
181+
endDate.setMonth(endDate.getMonth() + 1);
182+
endDate.setDate(1);
183+
173184
sqls.push(
174185
...moveDataBetweenTables({
175186
from: 'sessions',
@@ -215,6 +226,7 @@ export async function up() {
215226
],
216227
batch: {
217228
startDate: firstSessionDate,
229+
endDate: endDate,
218230
column: 'toDate(created_at)',
219231
interval: 'month',
220232
transform: (date: Date) => {

packages/db/code-migrations/migrate.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ async function migrate() {
5959
if (!getIsDry()) {
6060
printBoxMessage('🕒 Migrations starts in 10 seconds', []);
6161
await new Promise((resolve) => setTimeout(resolve, 10000));
62+
} else {
63+
printBoxMessage('🕒 Migrations starts now (dry run)', []);
6264
}
6365
}
6466

0 commit comments

Comments
 (0)