@firebaseextensions/firestore-bigquery-change-tracker 1.1.17 → 1.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.viewRequiresUpdate = exports.tableRequiresUpdate = void 0;
4
4
  const partitioning_1 = require("./partitioning");
5
- async function tableRequiresUpdate({ table, config, documentIdColExists, pathParamsColExists, }) {
5
+ async function tableRequiresUpdate({ table, config, documentIdColExists, pathParamsColExists, oldDataColExists, }) {
6
6
  /* Setup checks */
7
7
  const { metadata } = table;
8
8
  /** Check clustering */
@@ -16,6 +16,9 @@ async function tableRequiresUpdate({ table, config, documentIdColExists, pathPar
16
16
  /** Check document id column */
17
17
  if (!documentIdColExists)
18
18
  return true;
19
+ /** Check old_data column exists */
20
+ if (!oldDataColExists)
21
+ return true;
19
22
  /** Check partitioning */
20
23
  const partitioning = new partitioning_1.Partitioning(config, table);
21
24
  const isValidPartition = await partitioning.isValidPartitionForExistingTable();
@@ -25,16 +28,16 @@ async function tableRequiresUpdate({ table, config, documentIdColExists, pathPar
25
28
  return false;
26
29
  }
27
30
  exports.tableRequiresUpdate = tableRequiresUpdate;
28
- function viewRequiresUpdate({ metadata, config, documentIdColExists, pathParamsColExists, }) {
29
- /** Check if documentId column exists */
30
- if (!documentIdColExists)
31
- return true;
31
+ function viewRequiresUpdate({ metadata, config, documentIdColExists, pathParamsColExists, oldDataColExists, }) {
32
32
  /** Check wildcards */
33
33
  if (!!config.wildcardIds !== pathParamsColExists)
34
34
  return true;
35
35
  /** Check document id column */
36
36
  if (!documentIdColExists)
37
37
  return true;
38
+ /** Check old_data column exists */
39
+ if (!oldDataColExists)
40
+ return true;
38
41
  /* Using the new query syntax for snapshots */
39
42
  if (metadata) {
40
43
  const query = metadata.view?.query || "";
@@ -253,6 +253,11 @@ class FirestoreBigQueryEventHistoryTracker {
253
253
  await clustering.updateClustering(metadata);
254
254
  const documentIdColExists = fields.find((column) => column.name === "document_id");
255
255
  const pathParamsColExists = fields.find((column) => column.name === "path_params");
256
+ const oldDataColExists = fields.find((column) => column.name === "old_data");
257
+ if (!oldDataColExists) {
258
+ fields.push(schema_1.oldDataField);
259
+ logs.addNewColumn(this.rawChangeLogTableName(), schema_1.oldDataField.name);
260
+ }
256
261
  if (!documentIdColExists) {
257
262
  fields.push(schema_1.documentIdField);
258
263
  logs.addNewColumn(this.rawChangeLogTableName(), schema_1.documentIdField.name);
@@ -261,16 +266,26 @@ class FirestoreBigQueryEventHistoryTracker {
261
266
  fields.push(schema_1.documentPathParams);
262
267
  logs.addNewColumn(this.rawChangeLogTableName(), schema_1.documentPathParams.name);
263
268
  }
264
- await partitioning.addPartitioningToSchema(metadata.schema.fields);
265
269
  /** Updated table metadata if required */
266
270
  const shouldUpdate = await checkUpdates_1.tableRequiresUpdate({
267
271
  table,
268
272
  config: this.config,
269
273
  documentIdColExists,
270
274
  pathParamsColExists,
275
+ oldDataColExists,
271
276
  });
272
277
  if (shouldUpdate) {
278
+ /** set partitioning */
279
+ await partitioning.addPartitioningToSchema(metadata.schema.fields);
280
+ /** update table metadata with changes. */
273
281
  await table.setMetadata(metadata);
282
+ logs.updatingMetadata(this.rawChangeLogTableName(), {
283
+ table,
284
+ config: this.config,
285
+ documentIdColExists,
286
+ pathParamsColExists,
287
+ oldDataColExists,
288
+ });
274
289
  }
275
290
  }
276
291
  else {
@@ -307,18 +322,22 @@ class FirestoreBigQueryEventHistoryTracker {
307
322
  if (viewExists) {
308
323
  logs.bigQueryViewAlreadyExists(view.id, dataset.id);
309
324
  const [metadata] = await view.getMetadata();
310
- const fields = metadata.schema ? metadata.schema.fields : [];
325
+ // TODO: just casting this for now, needs properly fixing
326
+ const fields = (metadata.schema ? metadata.schema.fields : []);
311
327
  if (this.config.wildcardIds) {
312
328
  schema.fields.push(schema_1.documentPathParams);
313
329
  }
314
- const documentIdColExists = fields.find((column) => column.name === "document_id");
315
- const pathParamsColExists = fields.find((column) => column.name === "path_params");
330
+ const columnNames = fields.map((field) => field.name);
331
+ const documentIdColExists = columnNames.includes("document_id");
332
+ const pathParamsColExists = columnNames.includes("path_params");
333
+ const oldDataColExists = columnNames.includes("old_data");
316
334
  /** If new view or opt-in to new query syntax **/
317
335
  const updateView = checkUpdates_1.viewRequiresUpdate({
318
336
  metadata,
319
337
  config: this.config,
320
338
  documentIdColExists,
321
339
  pathParamsColExists,
340
+ oldDataColExists,
322
341
  });
323
342
  if (updateView) {
324
343
  metadata.view = snapshot_1.latestConsistentSnapshotView({
@@ -327,8 +346,17 @@ class FirestoreBigQueryEventHistoryTracker {
327
346
  schema,
328
347
  useLegacyQuery: !this.config.useNewSnapshotQuerySyntax,
329
348
  });
330
- logs.addNewColumn(this.rawLatestView(), schema_1.documentIdField.name);
349
+ if (!documentIdColExists) {
350
+ logs.addNewColumn(this.rawLatestView(), schema_1.documentIdField.name);
351
+ }
331
352
  await view.setMetadata(metadata);
353
+ logs.updatingMetadata(this.rawLatestView(), {
354
+ metadata,
355
+ config: this.config,
356
+ documentIdColExists,
357
+ pathParamsColExists,
358
+ oldDataColExists,
359
+ });
332
360
  }
333
361
  }
334
362
  else {
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getNewPartitionField = exports.RawChangelogSchema = exports.RawChangelogViewSchema = exports.documentPathParams = exports.documentIdField = exports.longitudeField = exports.latitudeField = exports.timestampField = exports.operationField = exports.eventIdField = exports.documentNameField = exports.dataField = void 0;
18
+ exports.getNewPartitionField = exports.RawChangelogSchema = exports.RawChangelogViewSchema = exports.oldDataField = exports.documentPathParams = exports.documentIdField = exports.longitudeField = exports.latitudeField = exports.timestampField = exports.operationField = exports.eventIdField = exports.documentNameField = exports.dataField = void 0;
19
19
  const bigQueryField = (name, type, mode, fields) => ({
20
20
  fields,
21
21
  mode: mode || "NULLABLE",
@@ -43,6 +43,12 @@ exports.documentPathParams = {
43
43
  type: "STRING",
44
44
  description: "JSON string representing wildcard params with Firestore Document ids",
45
45
  };
46
+ exports.oldDataField = {
47
+ name: "old_data",
48
+ mode: "NULLABLE",
49
+ type: "STRING",
50
+ description: "The full JSON representation of the document state before the indicated operation is applied. This field will be null for CREATE operations.",
51
+ };
46
52
  /*
47
53
  * We cannot specify a schema for view creation, and all view columns default
48
54
  * to the NULLABLE mode.
package/lib/logs.js CHANGED
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.failedToInitializeWait = exports.tableCreationError = exports.invalidClustering = exports.hourAndDatePartitioningWarning = exports.invalidTableReference = exports.invalidProjectIdWarning = exports.cannotPartitionExistingTable = exports.removedClustering = exports.updatedClustering = exports.bigQueryTableInsertErrors = exports.firestoreTimePartitioningParametersWarning = exports.firestoreTimePartitionFieldError = exports.addPartitionFieldColumn = exports.addNewColumn = exports.timestampMissingValue = exports.error = exports.dataTypeInvalid = exports.dataInserting = exports.dataInsertRetried = exports.dataInserted = exports.complete = exports.bigQueryViewValidating = exports.bigQueryViewValidated = exports.bigQueryViewUpToDate = exports.bigQueryViewUpdating = exports.bigQueryViewUpdated = exports.bigQueryViewAlreadyExists = exports.bigQueryViewCreating = exports.bigQueryViewCreated = exports.bigQueryUserDefinedFunctionCreated = exports.bigQueryUserDefinedFunctionCreating = exports.bigQueryTableValidating = exports.bigQueryTableValidated = exports.bigQueryTableUpToDate = exports.bigQueryTableUpdating = exports.bigQueryTableUpdated = exports.bigQueryTableCreating = exports.bigQueryTableCreated = exports.bigQueryTableAlreadyExists = exports.bigQuerySchemaViewCreated = exports.bigQueryLatestSnapshotViewQueryCreated = exports.bigQueryErrorRecordingDocumentChange = exports.bigQueryDatasetExists = exports.bigQueryDatasetCreating = exports.bigQueryDatasetCreated = exports.arrayFieldInvalid = void 0;
18
+ exports.updatingMetadata = exports.failedToInitializeWait = exports.tableCreationError = exports.invalidClustering = exports.hourAndDatePartitioningWarning = exports.invalidTableReference = exports.invalidProjectIdWarning = exports.cannotPartitionExistingTable = exports.removedClustering = exports.updatedClustering = exports.bigQueryTableInsertErrors = exports.firestoreTimePartitioningParametersWarning = exports.firestoreTimePartitionFieldError = exports.addPartitionFieldColumn = exports.addNewColumn = exports.timestampMissingValue = exports.error = exports.dataTypeInvalid = exports.dataInserting = exports.dataInsertRetried = exports.dataInserted = exports.complete = exports.bigQueryViewValidating = exports.bigQueryViewValidated = exports.bigQueryViewUpToDate = exports.bigQueryViewUpdating = exports.bigQueryViewUpdated = exports.bigQueryViewAlreadyExists = exports.bigQueryViewCreating = exports.bigQueryViewCreated = exports.bigQueryUserDefinedFunctionCreated = exports.bigQueryUserDefinedFunctionCreating = exports.bigQueryTableValidating = exports.bigQueryTableValidated = exports.bigQueryTableUpToDate = exports.bigQueryTableUpdating = exports.bigQueryTableUpdated = exports.bigQueryTableCreating = exports.bigQueryTableCreated = exports.bigQueryTableAlreadyExists = exports.bigQuerySchemaViewCreated = exports.bigQueryLatestSnapshotViewQueryCreated = exports.bigQueryErrorRecordingDocumentChange = exports.bigQueryDatasetExists = exports.bigQueryDatasetCreating = exports.bigQueryDatasetCreated = exports.arrayFieldInvalid = void 0;
19
19
  const firebase_functions_1 = require("firebase-functions");
20
20
  exports.arrayFieldInvalid = (fieldName) => {
21
21
  firebase_functions_1.logger.warn(`Array field '${fieldName}' does not contain an array, skipping`);
@@ -173,3 +173,6 @@ exports.tableCreationError = (table, message) => {
173
173
  exports.failedToInitializeWait = (message) => {
174
174
  firebase_functions_1.logger.warn(`Failed while waiting to initialize.`, message);
175
175
  };
176
+ exports.updatingMetadata = (tableName, resources) => {
177
+ firebase_functions_1.logger.info(`Updated Metadata on ${tableName}, ${JSON.stringify(resources)})`);
178
+ };
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "github.com/firebase/extensions.git",
6
6
  "directory": "firestore-bigquery-export/firestore-bigquery-change-tracker"
7
7
  },
8
- "version": "1.1.17",
8
+ "version": "1.1.19",
9
9
  "description": "Core change-tracker library for Cloud Firestore Collection BigQuery Exports",
10
10
  "main": "./lib/index.js",
11
11
  "scripts": {