FireStore:在没有源代码控制的情况下更改查找表



我想创建一个包含查找表的Firestore数据库。我们正在使用Java 8与Github/Intellij。我们正在考虑使用这个例子,我如何种子数据到Firebase Firestore?每个日历季度播种/更新查找表数据。

是否有办法在使用Java(或任何其他编码语言)的Firestore中播种/更新数据,同时避免对Git源代码控制进行更改?谷歌推荐的方式是什么?更改需要在Devops环境、Dev、QA、Staging、Production中自动进行。ProductOwners团队需要能够在UI中更改更改,如果可能的话,不使用代码。

javahttps://firebase.google.com/docs/firestore/manage-data/add-data

{
id: 1,
productName: 'Book',
description: 'reading books',
id: 2,
productName: 'Car',
description: 'automobile cars used for driving',
id: 3,
productName: 'Television',
description: 'Screen used for watching items',
etc..
}

  1. 将种子数据添加到利益相关者具有读写权限的Firestore集合
  2. 创建一个由FirestoreonWrite事件触发的云函数,将给定的更改传播到目标位置

上面链接的文档中的示例展示了如何使用Firebase Admin SDK在NodeJS中创建Cloud Function。对于Java,您可以使用Firestore文档中的这个示例:

import com.google.cloud.functions.Context;
import com.google.cloud.functions.RawBackgroundFunction;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.util.logging.Logger;
public class FirebaseFirestore implements RawBackgroundFunction {
private static final Logger logger = Logger.getLogger(FirebaseFirestore.class.getName());
// Use GSON (https://github.com/google/gson) to parse JSON content.
private static final Gson gson = new Gson();
@Override
public void accept(String json, Context context) {
JsonObject body = gson.fromJson(json, JsonObject.class);
logger.info("Function triggered by event on: " + context.resource());
logger.info("Event type: " + context.eventType());
if (body != null && body.has("oldValue")) {
logger.info("Old value:");
logger.info(body.get("oldValue").getAsString());
}
if (body != null && body.has("value")) {
logger.info("New value:");
logger.info(body.get("value").getAsString());
}
}
}

或者你可以使用CloudEvent触发器为Gen 2云功能:

package mycloudeventfunction;
import com.google.cloud.functions.CloudEventsFunction;
import io.cloudevents.CloudEvent;
// Define a class that implements the CloudEventsFunction interface
public class MyCloudEventFunction implements CloudEventsFunction {
// Implement the accept() method to handle CloudEvents
@Override
public void accept(CloudEvent event) {
// Your code here
// Access the CloudEvent data payload via event.getData()
// To get the data payload as a JSON string, use:
// new String(event.getData().toBytes())
}
}

你需要调整这个例子,通过解析CloudEvents的JSON格式来为Cloud Firestore使用适当的EventArc触发器。不幸的是,在谷歌的文档中似乎没有任何直接的例子,因为第2代功能仍然相对较新。

相关内容