How to code a simple versioning system?

Boris Guéry picture Boris Guéry · Jun 9, 2009 · Viewed 10k times · Source

I want to do a simple versioning system but i don't have ideas on how to structure my datas, and my code.

Here is a short example:

  1. User logs in
  2. User has two options when uploading a file:
    • Submit a new file
    • Submit a new version of a file

Users should be able to see the tree. (the different version) The tree can only be up to 2 levels:

|
|--File_A_0
 \--File_A_1
 \--File_A_2
 \--File_A_3
 \--File_A_4

There are also 2 types of file, a final (which is the latest approved version) and a draft version (which the latest uploaded file) The file will be physically stored on the server. Each files are owned by a user (or more) and only one group.

Edit: Groups represent a group of document, document could only be owned by ONE group at once. Users do NOT depend on groups.

Begin edit:

Here is what i did, but it is not really efficient !

id_article | relative_group_id | id_group | title | submited | date | abstract | reference | draft_version | count | status

id_draft | id_file | version | date

But it's difficult to manage, to extend. I think it's because the group paramater...

End edit

So the questions are:

  • How can i schematize my database ?
  • What kind of infos should be usefull to version this work ?
  • What kind of structure for the folders, files ?
  • What kind of tips, hints do you have to do this kind of work ?

(The application is developped with PHP and Zend Framework, database should be mysql or postgresql)

Answer

Michael Dorfman picture Michael Dorfman · Jun 15, 2009

For God's sake, don't. You really don't want to go down this road.

Stop and think about the bigger picture for a moment. You want to keep earlier versions of documents, which means that at some point, somebody is going to want to see some of those earlier versions, right? And then they are going to ask, "What's the difference between version 3 and version 7"? And then they are going to say, "I want to roll back to version 3, but keep some of the changes that I put in version 5, ummm, ok?"

Version control is non-trivial, and there's no need to reinvent the wheel-- there are lots of viable version control systems out there, some of them free, even.

In the long run, it will be much easier to learn the API of one of these systems, and code a web front-end that offers your users the subset of features they are looking for (now.)

You wouldn't code a text editor for your users, would you?