Source code for airflow.providers.google.firebase.example_dags.example_firestore
## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License."""Example Airflow DAG that shows interactions with Google Cloud Firestore.Prerequisites=============This example uses two Google Cloud projects:* ``GCP_PROJECT_ID`` - It contains a bucket and a firestore database.* ``G_FIRESTORE_PROJECT_ID`` - it contains the Data Warehouse based on the BigQuery service.Saving in a bucket should be possible from the ``G_FIRESTORE_PROJECT_ID`` project.Reading from a bucket should be possible from the ``GCP_PROJECT_ID`` project.The bucket and dataset should be located in the same region.If you want to run this example, you must do the following:1. Create Google Cloud project and enable the BigQuery API2. Create the Firebase project3. Create a bucket in the same location as the Firebase project4. Grant Firebase admin account permissions to manage BigQuery. This is required to create a dataset.5. Create a bucket in Firebase project and6. Give read/write access for Firebase admin to bucket to step no. 5.7. Create collection in the Firestore database."""importosfromdatetimeimportdatetimefromurllib.parseimporturlparsefromairflowimportmodelsfromairflow.models.baseoperatorimportchainfromairflow.providers.google.cloud.operators.bigqueryimport(BigQueryCreateEmptyDatasetOperator,BigQueryCreateExternalTableOperator,BigQueryDeleteDatasetOperator,BigQueryInsertJobOperator,)fromairflow.providers.google.firebase.operators.firestoreimportCloudFirestoreExportDatabaseOperator
ifBUCKET_NAMEisNone:raiseValueError("Bucket name is required. Please set GCP_FIRESTORE_ARCHIVE_URL env variable.")withmodels.DAG("example_google_firestore",start_date=datetime(2021,1,1),schedule_interval='@once',catchup=False,tags=["example"],)asdag:# [START howto_operator_export_database_to_gcs]