在没有 SQL 复制的情况下保持 Rails 应用程序之间的表同步?

发布于 2024-07-17 11:27:06 字数 354 浏览 3 评论 0原文

我有一个 Rails 应用程序,它使用两个与我拥有的另一个 Rails 应用程序相同的模型。 在两个模型之间保持数据同步的最佳方法是什么?

由于托管限制,并且引用复制数据的内容是依赖的,MySQL 复制可能无法实现=> :destroy 意味着 mysql 复制将导致指向已删除的复制数据的内容保留下来。

简而言之,在应用程序级别基于每个模型在两个 Rails 应用程序之间进行复制的最佳方法是什么? 我是否必须使用 REST 来破解我自己的复制,或者有更好的方法吗?

我应该补充一点,数据很少更改,每天最多更改几次,并且集合始终小于 50k 行。

编辑:为了回应托比下面的评论,数据都是单向的。

I have a rails app that uses two of the same models as another rails app I have. What's the best way to keep data synced between two models?

MySQL replication probably won't be possible due to hosting restrictions and since stuff that references the replicated data is dependent => :destroy meaning mysql replication will cause stuff that points to replicated data that is deleted to remain.

In short, what's the best way to do replication between two rails apps, on a per-model basis, at the application level? Am I going to have to hack my own replication using REST, or is there a better way?

I should add that data changes infrequently, at most a few times a day, and the set will always be less than 50k rows.

Edit: In response to Toby's comment below, the data is all going one way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

源来凯始玺欢你 2024-07-24 11:27:06

这不是一个具体的答案,但请考虑某种排队机制。 应用程序 A 进行更改并写入队列和数据库。 “队列”可以是数据库中的一个表,上面写着“应用程序 A 使用 id I 更改了模型 M”。 然后,两个应用程序都可以有一个进程来轮询该表并应用更改。

当双方都修改同一个对象时,就会遇到麻烦。

This isn't a specific answer but consider some sort of queuing mechanism. App A makes a change and writes to both a queue and the database. The "queue" could be a table in the database that says "App A changed Model M with id I". Both apps could then have a process that polls this table and applies the changes.

Where you will run into trouble is when both sides modify the same object.

肩上的翅膀 2024-07-24 11:27:06

因此,事实证明有两个插件可以执行此操作:

充当副本

充当可同步

充当副本似乎有更好的文档。

然而,考虑到它的复杂性,我认为为了我自己的需求,我将推出自己的,虽然不完美,但对于我自己的用例来说会简单得多。

我的复制表中的所有数据都是从 XML 文件中简单地挑选出来的。 出于隐私原因,XML 无法完整发送到要复制的服务器(我只在两个应用程序中使用一个子集,但额外的数据是敏感的),因此我将只公开一个包含我的数据的 REST 接口需要并复制它。

So, it turns out there are two plugins that do this:

Acts as Replica
and
Acts as Syncable

Acts as Replica seems to have better documentation.

Looking at the complexity of it however, I think for my own needs I'm going to roll my own that, while not perfect will be far simpler for my own use case.

All the data in my replicated tables is simply culled from an XML file. The XML cannot be sent in full to the server to be replicated to for privacy reasons (I only use a subset in both apps, but the extra data is sensitive), so I'm going to just expose a REST interface with the data I need and replicate that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文