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:
To keep it exremely simple, I would choose the following database design. I'm separating the "file" (same as a filesystem file) concept from the "document" (the gerarchic group of documents) concept.
User entity:
Group entity:
File entity:
Document entity:
Every time a new file is uploaded, a "File" record is created, and also a new "Document". If it's the first time that file is uploaded, parentDocumentId for that document would be NULL. Otherwise, the new document record would point to the first version.
The "isApproved" field (boolean) would handle the document being a draft or an approved revision.
You get the latest draft of a document simply ordering descending by version number or upload time.
From how you describe the problem, you should analyze better those aspects, before moving to database schema design:
Hope this helps.