Skip to content

Commit 442722a

Browse files
authored
refactor: improve partitioning code (#2447)
* refactor: improve partitioning code * fix(firestore-bigquery-change-tracker): update imports * fix(firestore-bigquery-export): make sure tests are running correctly with the correct project ID
1 parent 7f52a39 commit 442722a

28 files changed

+1856
-835
lines changed

firestore-bigquery-export/CONTRIBUTING.md

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Development Setup
22

3-
The firestore-bigquery-export extension is split out into 4 node.js packages, three of
4-
which are hosted on [npm](https://www.npmjs.com/search?q=firebaseextensions).
3+
The firestore-bigquery-export extension is split out into 4 node.js packages,
4+
three of which are hosted on
5+
[npm](https://www.npmjs.com/search?q=firebaseextensions).
56

67
**[firestore-bigquery-change-tracker](https://www.npmjs.com/package/@firebaseextensions/firestore-bigquery-change-tracker)**:
7-
Contains the core interface defintions for document changes. Also exposes an
8-
API for uploading changes to BigQuery. The business-logic associated with
9-
creating the raw changelog and the latest snapshot of live documents in the
10-
changelog also lives in this package. This package is a dependency for all 3 other packages.
8+
Contains the core interface defintions for document changes. Also exposes an API
9+
for uploading changes to BigQuery. The business-logic associated with creating
10+
the raw changelog and the latest snapshot of live documents in the changelog
11+
also lives in this package. This package is a dependency for all 3 other
12+
packages.
1113

1214
**[fs-bq-import-collection](https://www.npmjs.com/package/@firebaseextensions/fs-bq-import-collection)**:
1315
Contains a script for resumably importing a firestore collection into BigQuery
@@ -17,10 +19,10 @@ using the interface definitions in `firestore-bigquery-change-tracker`.
1719
Contains a script for generating BigQuery views that provide typed-checked
1820
access to the changelog created in `firestore-bigquery-change-tracker`.
1921

20-
**firestore-bigquery-export-functions (a part of the extension)**: Contains the definition
21-
for a Google Cloud function that is called on each write to some collection.
22-
The function constructs the relevant change event and calls the API in
23-
`firestore-bigquery-change-tracker` to upload the change to BigQuery.
22+
**firestore-bigquery-export-functions (a part of the extension)**: Contains the
23+
definition for a Google Cloud function that is called on each write to some
24+
collection. The function constructs the relevant change event and calls the API
25+
in `firestore-bigquery-change-tracker` to upload the change to BigQuery.
2426

2527
## Building Locally
2628

@@ -40,10 +42,10 @@ done;
4042

4143
### Local package.json file pointers
4244

43-
Npm supports using [local paths as
44-
dependencies](https://docs.npmjs.com/files/package.json#local-paths) in package.json.
45-
You'll need to update the following package.json files with local pointers to
46-
the firestore-bigquery-change-tracker package:
45+
Npm supports using
46+
[local paths as dependencies](https://docs.npmjs.com/files/package.json#local-paths)
47+
in package.json. You'll need to update the following package.json files with
48+
local pointers to the firestore-bigquery-change-tracker package:
4749

4850
1. firestore-bigquery-export/package.json
4951
1. firestore-bigquery-export/scripts/import/package.json
@@ -73,6 +75,45 @@ do
7375
done;
7476
```
7577

78+
## Running Integration Tests
79+
80+
Some tests (particularly in `firestore-bigquery-change-tracker`) are integration
81+
tests that make real calls to BigQuery. These require GCP authentication to be
82+
configured correctly.
83+
84+
### Prerequisites
85+
86+
1. **Set your GCP project:**
87+
88+
```bash
89+
gcloud config set project <your-gcp-project-id>
90+
```
91+
92+
2. **Set the quota project for Application Default Credentials:**
93+
94+
```bash
95+
gcloud auth application-default set-quota-project <your-gcp-project-id>
96+
```
97+
98+
3. **Set the `PROJECT_ID` environment variable** (some tests read this):
99+
```bash
100+
export PROJECT_ID=<your-gcp-project-id>
101+
```
102+
103+
### Running Tests
104+
105+
From the `firestore-bigquery-change-tracker` directory:
106+
107+
```bash
108+
npm test
109+
```
110+
111+
Or to run a specific test file:
112+
113+
```bash
114+
npx jest src/__tests__/bigquery/partitioning.test.ts --no-coverage
115+
```
116+
76117
## Publishing
77118

78119
_The following instructions are for Firebase team members only._
@@ -87,9 +128,15 @@ npm pack
87128
npm publish
88129
```
89130

90-
In general, you should publish `firestore-bigquery-change-tracker` first, since it doesn't depend on anything else, and all other packages depend on it. Follow these steps:
131+
In general, you should publish `firestore-bigquery-change-tracker` first, since
132+
it doesn't depend on anything else, and all other packages depend on it. Follow
133+
these steps:
91134

92-
1. Publish the package to NPM once the PR has been approved, by checking out the branch.
93-
1. If a critical bug fix has been made to `firestore-bigquery-change-tracker`, update the dependency version in all 3 other packages. Publish `fs-bq-import-collection` and `fs-bq-schema-views` to NPM.
135+
1. Publish the package to NPM once the PR has been approved, by checking out the
136+
branch.
137+
1. If a critical bug fix has been made to `firestore-bigquery-change-tracker`,
138+
update the dependency version in all 3 other packages. Publish
139+
`fs-bq-import-collection` and `fs-bq-schema-views` to NPM.
94140
1. Merge the PR to `next` branch
95-
1. If `firestore-bigquery-export-functions` had any changes in code or `package.json`, an extension release is required.
141+
1. If `firestore-bigquery-export-functions` had any changes in code or
142+
`package.json`, an extension release is required.

firestore-bigquery-export/firestore-bigquery-change-tracker/package-lock.json

Lines changed: 16 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firestore-bigquery-export/firestore-bigquery-change-tracker/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url": "github.com/firebase/extensions.git",
66
"directory": "firestore-bigquery-export/firestore-bigquery-change-tracker"
77
},
8-
"version": "1.1.42",
8+
"version": "2.0.0",
99
"description": "Core change-tracker library for Cloud Firestore Collection BigQuery Exports",
1010
"main": "./lib/index.js",
1111
"scripts": {
@@ -50,6 +50,7 @@
5050
"nyc": "^17.1.0",
5151
"rimraf": "^2.6.3",
5252
"ts-jest": "29.1.2",
53-
"typescript": "^4.9.4"
53+
"typescript": "^4.9.4",
54+
"wait-for-expect": "^3.0.2"
5455
}
5556
}

0 commit comments

Comments
 (0)