@@ -26,6 +26,7 @@ import { readSchemas } from "./schema-loader-utils";
26
26
27
27
const BIGQUERY_VALID_CHARACTERS = / ^ [ a - z A - Z 0 - 9 _ ] + $ / ;
28
28
const FIRESTORE_VALID_CHARACTERS = / ^ [ ^ \/ ] + $ / ;
29
+ const GCP_PROJECT_VALID_CHARACTERS = / ^ [ a - z ] [ a - z 0 - 9 - ] { 0 , 29 } $ / ;
29
30
30
31
const validateInput = ( value : any , name : string , regex : RegExp ) => {
31
32
if ( ! value || value === "" || value . trim ( ) === "" ) {
@@ -58,7 +59,7 @@ program
58
59
)
59
60
. option (
60
61
"-B, --big-query-project <big-query-project>" ,
61
- "Google Cloud Project ID for BigQuery."
62
+ "Google Cloud Project ID for BigQuery (can be the same as the Firebase project ID) ."
62
63
)
63
64
. option (
64
65
"-d, --dataset <dataset>" ,
@@ -79,10 +80,20 @@ const questions = [
79
80
{
80
81
message : "What is your Firebase project ID?" ,
81
82
name : "project" ,
83
+ default : process . env . PROJECT_ID ,
82
84
type : "input" ,
83
85
validate : ( value ) =>
84
86
validateInput ( value , "project ID" , FIRESTORE_VALID_CHARACTERS ) ,
85
87
} ,
88
+ {
89
+ message :
90
+ "What is your Google Cloud Project ID for BigQuery? (can be the same as the Firebase project ID)" ,
91
+ name : "bigQueryProject" ,
92
+ default : process . env . PROJECT_ID ,
93
+ type : "input" ,
94
+ validate : ( value ) =>
95
+ validateInput ( value , "BigQuery project ID" , GCP_PROJECT_VALID_CHARACTERS ) ,
96
+ } ,
86
97
{
87
98
message :
88
99
"What is the ID of the BigQuery dataset the raw changelog lives in? (The dataset and the raw changelog must already exist!)" ,
@@ -109,6 +120,7 @@ const questions = [
109
120
110
121
interface CliConfig {
111
122
projectId: string ;
123
+ bigQueryProjectId: string ;
112
124
datasetId: string ;
113
125
tableNamePrefix: string ;
114
126
schemas: { [ schemaName : string ] : FirestoreSchema } ;
@@ -121,7 +133,7 @@ async function run(): Promise<number> {
121
133
// Set project ID so it can be used in BigQuery intialization
122
134
process . env . PROJECT_ID = config . projectId ;
123
135
// BigQuery actually requires this variable to set the project correctly.
124
- process . env . GOOGLE_CLOUD_PROJECT = config . projectId ;
136
+ process . env . GOOGLE_CLOUD_PROJECT = config . bigQueryProjectId ;
125
137
126
138
// Initialize Firebase
127
139
if ( ! firebase . apps . length ) {
@@ -135,7 +147,9 @@ async function run(): Promise<number> {
135
147
if ( Object . keys ( config . schemas ) . length === 0 ) {
136
148
console . log ( `No schema files found!` ) ;
137
149
}
138
- const viewFactory = new FirestoreBigQuerySchemaViewFactory ( ) ;
150
+ const viewFactory = new FirestoreBigQuerySchemaViewFactory (
151
+ config . bigQueryProjectId
152
+ ) ;
139
153
for ( const schemaName in config . schemas ) {
140
154
await viewFactory . initializeSchemaViewResources (
141
155
config . datasetId ,
@@ -152,6 +166,7 @@ async function parseConfig(): Promise<CliConfig> {
152
166
if ( program . nonInteractive ) {
153
167
if (
154
168
program . project === undefined ||
169
+ program . bigQueryProject === undefined ||
155
170
program . dataset === undefined ||
156
171
program . tableNamePrefix === undefined ||
157
172
program . schemaFiles . length === 0
@@ -161,15 +176,18 @@ async function parseConfig(): Promise<CliConfig> {
161
176
}
162
177
return {
163
178
projectId : program . project ,
179
+ bigQueryProjectId : program . bigQueryProject ,
164
180
datasetId : program . dataset ,
165
181
tableNamePrefix : program . tableNamePrefix ,
166
182
schemas : readSchemas ( program . schemaFiles ) ,
167
183
} ;
168
184
}
169
- const { project, dataset, tableNamePrefix, schemaFiles } =
185
+ const { project, bigQueryProject , dataset, tableNamePrefix, schemaFiles } =
170
186
await inquirer . prompt ( questions ) ;
187
+
171
188
return {
172
189
projectId : project ,
190
+ bigQueryProjectId : bigQueryProject ,
173
191
datasetId : dataset ,
174
192
tableNamePrefix : tableNamePrefix ,
175
193
schemas : readSchemas (
0 commit comments