|
1 | 1 | import { FirestoreBigQueryEventHistoryTrackerConfig } from ".";
|
2 |
| -import { FirestoreDocumentChangeEvent } from ".."; |
| 2 | +import { ChangeType, FirestoreDocumentChangeEvent } from ".."; |
3 | 3 | import * as firebase from "firebase-admin";
|
4 | 4 |
|
5 | 5 | import * as logs from "../logs";
|
6 | 6 | import * as bigquery from "@google-cloud/bigquery";
|
7 | 7 | import * as functions from "firebase-functions";
|
8 | 8 | import { getNewPartitionField } from "./schema";
|
9 | 9 | import { BigQuery, TableMetadata } from "@google-cloud/bigquery";
|
10 |
| - |
11 | 10 | import { PartitionFieldType } from "../types";
|
12 | 11 |
|
13 | 12 | export class Partitioning {
|
@@ -195,11 +194,16 @@ export class Partitioning {
|
195 | 194 | Delete changes events have no data, return early as cannot partition on empty data.
|
196 | 195 | **/
|
197 | 196 | getPartitionValue(event: FirestoreDocumentChangeEvent) {
|
198 |
| - if (!event.data) return {}; |
| 197 | + // When old data is disabled and the operation is delete |
| 198 | + // the data and old data will be null |
| 199 | + if (event.data == null && event.oldData == null) return {}; |
199 | 200 |
|
200 | 201 | const firestoreFieldName = this.config.timePartitioningFirestoreField;
|
201 | 202 | const fieldName = this.config.timePartitioningField;
|
202 |
| - const fieldValue = event.data[firestoreFieldName]; |
| 203 | + const fieldValue = |
| 204 | + event.operation === ChangeType.DELETE |
| 205 | + ? event.oldData[firestoreFieldName] |
| 206 | + : event.data[firestoreFieldName]; |
203 | 207 |
|
204 | 208 | if (!fieldName || !fieldValue) {
|
205 | 209 | return {};
|
|
0 commit comments