Skip to content

Commit 4aae718

Browse files
authored
Merge pull request #2223 from firebase/@invertase/Extensions/firestore-bigquery-export/issue#2087
[Bug] Fix issue #2087: Handle multiple schema files in gen-schema-vie…
2 parents 8266204 + 718163a commit 4aae718

File tree

5 files changed

+130
-79
lines changed

5 files changed

+130
-79
lines changed

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

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

firestore-bigquery-export/scripts/gen-schema-view/src/__tests__/schema-loader-utils/schema-loader-utils.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,19 @@ describe("filesystem schema loading", () => {
7676
const schemas = schema_loader_utils.readSchemas([globPattern]);
7777
expect(Object.keys(schemas)).to.have.members(results);
7878
});
79+
it("should load schemas from a comma-separated list of file paths", () => {
80+
const schemaFiles = `${schemaDir}/full-directory/schema-1.json,${schemaDir}/full-directory/schema-2.json`;
81+
const schemas = Object.keys(schema_loader_utils.readSchemas([schemaFiles]));
82+
expect(schemas.length).to.equal(2);
83+
expect(schemas).to.include(
84+
schema_loader_utils.filePathToSchemaName(
85+
`${schemaDir}/full-directory/schema-1.json`
86+
)
87+
);
88+
expect(schemas).to.include(
89+
schema_loader_utils.filePathToSchemaName(
90+
`${schemaDir}/full-directory/schema-2.json`
91+
)
92+
);
93+
});
7994
});

firestore-bigquery-export/scripts/gen-schema-view/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ async function parseConfig(): Promise<CliConfig> {
174174
program.outputHelp();
175175
process.exit(1);
176176
}
177+
177178
return {
178179
projectId: program.project,
179180
bigQueryProjectId: program.bigQueryProject,

firestore-bigquery-export/scripts/gen-schema-view/src/schema-loader-utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ function resolveFilePath(filePath: string): string {
6363

6464
function expandGlobs(globs: string[]): string[] {
6565
let results = [];
66-
for (var i = 0; i < globs.length; i++) {
67-
const globResults = glob.sync(globs[i]);
66+
// Split any comma-separated globs into individual paths
67+
const expandedGlobs = globs.flatMap((g) => g.split(",").map((s) => s.trim()));
68+
for (const globPath of expandedGlobs) {
69+
const globResults = glob.sync(globPath);
6870
results = results.concat(globResults);
6971
}
7072
return results;

0 commit comments

Comments
 (0)