@@ -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 ) => {
0 commit comments