简体   繁体   English

如何将生产数据存储到Rails应用程序中的报表数据库?

[英]How to to store production data to a reporting DB in a Rails app?

We want to keep track of production data of a Rails app, so that we can analyse them in a few months. 我们希望跟踪Rails应用的生产数据,以便我们可以在几个月内对其进行分析。

To be more precise, we have a few data Models with a "status" and dates column that can change frequently. 更准确地说,我们有一些带有“状态”和日期列的数据模型,这些模型可以经常更改。 The idea is to write somewhere a new line in a DB or log file every time the status or any other attribute changes. 想法是每当状态或任何其他属性更改时,在数据库或日志文件中的某处写一行新行。 These line consists in a copy of all the attributes for this object. 这些行包含此对象的所有属性的副本。

I see different solutions: 我看到了不同的解决方案:

  • using observer with after_save, and replicate the saved data to a reporting Mysql Db 使用带有after_save的观察者,并将保存的数据复制到报告Mysql Db
  • using a logger system. 使用记录器系统。
  • do it a different level, on the DB level, detecting changes in a table and copying the affected rows to the reporting DB. 在数据库级别上执行另一级别的操作,检测表中的更改并将受影响的行复制到报告数据库中。

It's easier to extract data then if they are stored in a DB. 如果将数据存储在数据库中,则提取数据会更容易。 Log files are faster and don't slow down the process that much. 日志文件速度更快,并且不会大大减慢该过程。 I can't figure out what is the best way or if there is any other solution/implementation. 我不知道什么是最好的方法,或者是否有其他解决方案/实现。

have you looked at acts_as_versioned? 你看过act_as_versioned吗? I'm sure there is a more modern library written for this purpose, but it might accomplish what you need: versioning the data on update so you can keep track of it later. 我敢肯定有一个为此目的编写的更现代的库,但是它可以满足您的需要:在更新时对数据进行版本控制,以便以后可以对其进行跟踪。 It may give you a template to go by, anyway. 无论如何,它可能会为您提供模板。

There is an option as a gem: http://github.com/andersondias/acts_as_auditable 有一个宝石选项: http : //github.com/andersondias/acts_as_auditable

Now I'm hesitating between saving in a audit table or saving in file with CVS format. 现在,我在保存到审计表中还是以CVS格式保存文件之间犹豫不决。 My feeling is that the second option is better, because writting in file is faster and we don't depend on a connexion to a database server. 我的感觉是第二种方法更好,因为在文件中写入速度更快,而且我们不依赖于与数据库服务器的连接。

Any single BI tool is able to use a CVS file as a data source. 任何单个BI工具都可以将CVS文件用作数据源。 The problem is I have to create a different file each time I change the structure of my table. 问题是每次更改表的结构时,我必须创建一个不同的文件。 But is it a problem ? 但这有问题吗?

I finally used an observer, and a Logger with FasterCSV to generate audit log. 最后,我使用了一个观察器和一个带有FasterCSV的记录器来生成审核日志。

I wasn't able to copy/paste all the code properly, so here is a link to a blog post, for those who are interested: 我无法正确复制/粘贴所有代码,因此对于有兴趣的人,这里是博客文章的链接:

log rails production data to perform some audit (bi) 记录Rails生产数据以执行一些审核(bi)

This can be easily adapted for any Rails Model. 这可以轻松地适用于任何Rails模型。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM