def test_instance_export_missing_project_id(self, mock_hook): mock_hook.return_value.export_instance.return_value = True op = CloudSQLExportInstanceOperator(instance=INSTANCE_NAME, body=EXPORT_BODY, task_id="id") result = op.execute(None) mock_hook.assert_called_once_with(api_version="v1beta4", gcp_conn_id="google_cloud_default") mock_hook.return_value.export_instance.assert_called_once_with( project_id=None, instance=INSTANCE_NAME, body=EXPORT_BODY) self.assertTrue(result)
def test_instance_export(self, mock_hook): mock_hook.return_value.export_instance.return_value = True op = CloudSQLExportInstanceOperator(project_id=PROJECT_ID, instance=INSTANCE_NAME, body=EXPORT_BODY, task_id="id") result = op.execute(None) mock_hook.assert_called_once_with( api_version="v1beta4", gcp_conn_id="google_cloud_default", impersonation_chain=None, ) mock_hook.return_value.export_instance.assert_called_once_with( project_id=PROJECT_ID, instance=INSTANCE_NAME, body=EXPORT_BODY) assert result
# For export to work we need to add the Cloud SQL instance's Service Account # write access to the destination GCS bucket. # [START howto_operator_cloudsql_export_gcs_permissions] sql_gcp_add_bucket_permission_task = GCSBucketCreateAclEntryOperator( entity="user-{{ task_instance.xcom_pull(" "'sql_instance_create_task', key='service_account_email') " "}}", role="WRITER", bucket=export_url_split[1], # netloc (bucket) task_id='sql_gcp_add_bucket_permission_task') # [END howto_operator_cloudsql_export_gcs_permissions] # [START howto_operator_cloudsql_export] sql_export_task = CloudSQLExportInstanceOperator(project_id=GCP_PROJECT_ID, body=export_body, instance=INSTANCE_NAME, task_id='sql_export_task') sql_export_task2 = CloudSQLExportInstanceOperator( body=export_body, instance=INSTANCE_NAME, task_id='sql_export_task2') # [END howto_operator_cloudsql_export] # ############################################## # # ### IMPORTING SQL TO INSTANCE 2 ############## # # ############################################## # import_url_split = urlsplit(IMPORT_URI) # For import to work we need to add the Cloud SQL instance's Service Account # read access to the target GCS object. # [START howto_operator_cloudsql_import_gcs_permissions] sql_gcp_add_object_permission_task = GCSObjectCreateAclEntryOperator( entity="user-{{ task_instance.xcom_pull("
COALESCE(v.agua, 0) AS 'water', COALESCE(v.imc, 0) AS 'bmi', FROM_UNIXTIME(v.fecha_valoracion/1000, '%Y-%c-%d') AS 'date' FROM beneficiario_valoracion v LEFT JOIN usuario u ON v.beneficiario = u.id WHERE v.fecha_valoracion > 0 AND v.peso BETWEEN 30 and 300 AND v.estatura > 100 AND v.frecuencia_cardiaca > 40 AND u.nombre IS NOT NULL AND u.nacimiento_anio IS NOT NULL AND u.nacimiento_anio BETWEEN 1900 AND 2010 AND u.nacimiento_mes IS NOT NULL AND u.nacimiento_mes BETWEEN 1 AND 12 AND u.nacimiento_dia IS NOT NULL AND u.nacimiento_dia BETWEEN 1 AND 31; """ }, }, } export_db_tables = CloudSQLExportInstanceOperator( task_id="export_db_tables", project_id="uhma-303820", body=export_body, instance="uhma", poke_interval=5, timeout=20, )