| 591 | * Get min/max created_at for an import's staging data. |
| 592 | */ |
| 593 | export async function getImportDateBounds( |
| 594 | importId: string, |
| 595 | fromCreatedAt?: string |
| 596 | ): Promise<{ min: string | null; max: string | null }> { |
| 597 | const res = await ch.query({ |
| 598 | query: ` |
| 599 | SELECT min(created_at) AS min, max(created_at) AS max |
| 600 | FROM ${TABLE_NAMES.events_imports} |
| 601 | WHERE import_id = {importId:String} |
| 602 | AND name NOT IN ('session_start', 'session_end') |
| 603 | ${fromCreatedAt ? 'AND created_at >= {fromCreatedAt:String}' : ''} |
| 604 | `, |
| 605 | query_params: { importId, fromCreatedAt }, |
| 606 | format: 'JSONEachRow', |
| 607 | }); |
| 608 | const rows = (await res.json()) as Array<{ |
| 609 | min: string | null; |
| 610 | max: string | null; |
| 611 | }>; |
| 612 | return rows.length > 0 |
| 613 | ? { |
| 614 | min: fromCreatedAt ?? rows[0]?.min ?? null, |
| 615 | max: rows[0]?.max ?? null, |
| 616 | } |
| 617 | : { min: null, max: null }; |
| 618 | } |
| 619 | |
| 620 | export type UpdateImportStatusOptions = |
| 621 | | { |