Alex Rivera | Logout

How to code a simple versioning system?

Asked 2009-06-09T21:43:03.127
22

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)

Edit
Report

1 Answer

6

Creating a rich data structure in a traditional relational database such as MySQL can often be difficult, and there are much better ways of going about it. When working with a path based data structure with a hierarchy I like to create a flat-file based system that uses a data-serialization format such as JSON to store information about a specific file, directory or an entire repository.

This way you can use current available tools to navigate and manipulate the structure easily, and you can read, edit and understand the structure easily. XML is good for this too - it's slightly more verbose than JSON but easy to read and good for messaging and other XML-based systems too.

A quick example. If we have a repository that has a directory and three files. Looking at it front on it will look like this:

/repo
  /folder
    code.php
  file.txt
  image.jpg

We can have a metadata folder, which contains our JSON files, hidden from the OS, at the root of each directory, which describe that directory's contents. This is how traditional versioning systems work, except they use a custom language instead of JSON.

/repo
  */.folderdata*
  /code
    */.folderdata*
    code.php
  file.txt
  image.jpg

Each .folderdata folder could contain it's own structure that we can use to organize the folder's data properly. Each .folderdata folder could then be compressed to save disk space. If we look at the .folderdata folder inside the /code directory:

*/.folderdata*
  /revisions
    code.php.r1
    code.php.r2
    code.php.r3
  folderstructure.json
  filerevisions.json

The folder structure defines the structure of our folder, where the files and folders are in relation to one another etc. This could look something like this:

{
  '.':        'code',
  '..':       'repo',
  'code.php': {
    'author_id': 11543,
    'author
answered 2009-06-15T11:22:58.830

Your Answer