fix: set end date on migrations
This commit is contained in:
@@ -142,12 +142,18 @@ export async function up() {
|
|||||||
const firstEventDate = new Date(firstEventDateJson[0]?.created_at ?? '');
|
const firstEventDate = new Date(firstEventDateJson[0]?.created_at ?? '');
|
||||||
if (firstEventDate) {
|
if (firstEventDate) {
|
||||||
// Step 2: Copy data from old tables to new tables (partitioned by month for efficiency)
|
// 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(
|
sqls.push(
|
||||||
...moveDataBetweenTables({
|
...moveDataBetweenTables({
|
||||||
from: 'events',
|
from: 'events',
|
||||||
to: 'events_new_20251123',
|
to: 'events_new_20251123',
|
||||||
batch: {
|
batch: {
|
||||||
startDate: firstEventDate,
|
startDate: firstEventDate,
|
||||||
|
endDate: endDate,
|
||||||
column: 'toDate(created_at)',
|
column: 'toDate(created_at)',
|
||||||
interval: 'month',
|
interval: 'month',
|
||||||
transform: (date: Date) => {
|
transform: (date: Date) => {
|
||||||
@@ -170,6 +176,11 @@ export async function up() {
|
|||||||
|
|
||||||
const firstSessionDate = new Date(firstSessionDateJson[0]?.created_at ?? '');
|
const firstSessionDate = new Date(firstSessionDateJson[0]?.created_at ?? '');
|
||||||
if (firstSessionDate) {
|
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(
|
sqls.push(
|
||||||
...moveDataBetweenTables({
|
...moveDataBetweenTables({
|
||||||
from: 'sessions',
|
from: 'sessions',
|
||||||
@@ -215,6 +226,7 @@ export async function up() {
|
|||||||
],
|
],
|
||||||
batch: {
|
batch: {
|
||||||
startDate: firstSessionDate,
|
startDate: firstSessionDate,
|
||||||
|
endDate: endDate,
|
||||||
column: 'toDate(created_at)',
|
column: 'toDate(created_at)',
|
||||||
interval: 'month',
|
interval: 'month',
|
||||||
transform: (date: Date) => {
|
transform: (date: Date) => {
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ async function migrate() {
|
|||||||
if (!getIsDry()) {
|
if (!getIsDry()) {
|
||||||
printBoxMessage('🕒 Migrations starts in 10 seconds', []);
|
printBoxMessage('🕒 Migrations starts in 10 seconds', []);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 10000));
|
await new Promise((resolve) => setTimeout(resolve, 10000));
|
||||||
|
} else {
|
||||||
|
printBoxMessage('🕒 Migrations starts now (dry run)', []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user