0

I have a mysql db with Foo table and bar field as text.

I want keep hisorical of each change of the field.

For this moment I have hirtory table and I insert in db each version before update bar field.

But it's stupid to store all versions when the only change is one letter for exemple.

I want to use git instead of my hirtory table, how can I do that?

PS : I'm on app with ruby on rails 4.2

Matrix
  • 2,783
  • 6
  • 29
  • 59
  • I'm guessing that you are asking this question as the column stores a large amount of text (possibly for a wiki page, or maybe something different). I would suggest taking a look at how others have tackled the same (or similar) problems. [This answer](http://stackoverflow.com/a/323091/848668) has a couple of links that could be used as a starting point and give you some ideas. – br3nt Aug 17 '16 at 00:47
  • not realy long text, it's depend... It's articles of rule/law – Matrix Aug 17 '16 at 16:25

1 Answers1

2

Don't. Git is for managing source code, not database content. If you need to track changes in your database, using a history table is fine (as you're doing now), but there's also a great gem that takes care of this: https://github.com/airblade/paper_trail

joshua.paling
  • 12,854
  • 3
  • 38
  • 57
  • 1
    AFAIK, git doesn't distinguish between plain text and source code. It's a small nit in regards to your answer, but important to call out. I suppose the OP could devise a system in which a SQL dump is used (plain text) and then git versions that. But there's nothing stopping someone from using git to manage history of plain text (non-source code). – Jack Aug 17 '16 at 00:15
  • Yes, git manages text files - be it source code, or anything else. But not databases. Yes, you could do an SQL dump and track that in Git, but it's still a bad idea. Matrix can you elaborate more on your use case - why you want to store these versions, and what the domain is, rather than abstracting it as Foo and bar? Then we might be able to help with a better solution. – joshua.paling Aug 17 '16 at 11:08
  • It's not a problem if history with git is not in DB... Use case : user can write text of law, and I want show all version of each articles of law and show diff beetween them – Matrix Aug 17 '16 at 16:03