# 如何从插件添加 Data Explorer 查询？

**URL:** <https://meta.discourse.org/t/how-to-add-data-explorer-queries-automatically-from-a-plugin/368511>\
**Category:** Development\
**Created:** [2025年六月2日 09:30 UTC](https://meta.discourse.org/t/how-to-add-data-explorer-queries-automatically-from-a-plugin/368511 "2025-06-02T09:30:52Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)\
**Post date:** [2025年六月2日 09:30 UTC](https://meta.discourse.org/t/how-to-add-data-explorer-queries-automatically-from-a-plugin/368511/1 "2025-06-02T09:30:52Z")

</div>

我怀疑这里缺少一个 API。

[Data Explorer](https://meta.discourse.org/t/32566?silent=true) 作为插件工作流的一部分变得越来越有用，但是：

**我们如何可靠但宽容地从第三方插件添加 [Data Explorer](https://meta.discourse.org/t/32566?silent=true) 查询，以便我们能够优雅地失败而不会危及构建，同时也能在 [Data Explorer](https://meta.discourse.org/t/32566?silent=true) 最终安装时重试？**

我探索过的选项：

1. 轮询插件：这是一种作弊方式——查询是由 [Data Explorer](https://meta.discourse.org/t/32566?silent=true) 插件本身添加的
2. 插件固定数据 - 这似乎有问题，因为 [Data Explorer](https://meta.discourse.org/t/32566?silent=true) 的工件在插件初始化期间似乎不能保证可用——也许是因为 [Data Explorer](https://meta.discourse.org/t/32566?silent=true) 插件本身就是一个第三方插件，并且不能保证已被加载？我猜我可以尝试通过 Ruby 代码使用 SQL 来确定表是否存在？
3. 迁移 - 我已经编写了迁移，但它们需要无害地失败但 **不完成** ，如果 [Data Explorer](https://meta.discourse.org/t/32566?silent=true) 插件未安装且没有查询表——迁移应该始终在重建时运行，直到 [Data Explorer](https://meta.discourse.org/t/32566?silent=true) 插件安装并且表可用，这样查询就可以添加——这样从管理员的角度来看，解决方案是灵活的，不依赖于安装顺序。失败的迁移不应该危及构建——有没有办法在不停止构建的情况下失败/推迟迁移？
4. 使用定期的计划作业来检查数据探索器插件/查询表和所需查询是否存在。
5. 要求管理员手动添加它们……真糟糕。

我猜我接下来可能会尝试 2 的 SQL 版本，或者我错过了什么？

---

_[View the full topic](https://meta.discourse.org/t/how-to-add-data-explorer-queries-automatically-from-a-plugin/368511)._
