How to code a simple versioning system?

后端 未结 13 670
广开言路
广开言路 2021-01-30 11:27

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. U
13条回答
  •  执念已碎
    2021-01-30 12:03

    Database schema


    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:

    • userId
    • userName

    Group entity:

    • groupId
    • groupName

    File entity:

    • fileId (a sequence)
    • fileName (the name the user gives to the file)
    • filesystemFullPath
    • uploadTime
    • uploaderId (id of the uploader User)
    • ownerGroupId

    Document entity:

    • documentId
    • parentDocumentId
    • fileId
    • versionNumber
    • creationTime
    • isApproved

    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.

    Hints


    From how you describe the problem, you should analyze better those aspects, before moving to database schema design:

    • which is the role of the "group" entity?
    • how are groups/users/files related?
    • what if two users of different groups try to upload the same document?
    • will you need folders? (probably you will; my solution is still valid, giving a type, "folder" or "document", to the "document" entity)

    Hope this helps.

提交回复
热议问题