Logical system for directories

1

I have a system of directories in the bank

ex table directory:

id
parentDirID

parent dir means q is a subdirectory.

How would the "copy" directories function on the system? moving directories would just update the parentDirID, so I would just change places by logic. And to copy a directory with subdirectories? because if I generate a new directory with a different id, the old subdirectories will not point to the new one, and I can not create an equal ID as well because it would be wrong. What is the solution?

    
asked by anonymous 18.03.2015 / 15:52

1 answer

1

A copied directory is a new directory, so you need a new Id. the children will also create a new directory for each child, so each one needs a new ID.

Original table content (indentation is to show subdirectories):

id 1 - pastaA - parentDirID: null
    id 2 - pastaB - parentDirID: 1
        id 3 - pastaC - parentDirID: 2

id 4 - pastaD - parentDirID: null
    id 5 - pastaE - parentDirID: 4
        id 6 - pastaF - parentDirID: 5

Now we'll copy the pastaE down from pastaB .

New directories pastaE and pastaF will be generated, therefore new IDs. Table contents after copying:

id 1 - pastaA - parentDirID: null
    id 2 - pastaB - parentDirID: 1
        id 3 - pastaC - parentDirID: 2
        id 7 - pastaE - parentDirID: 2
            id 8 - pastaF - parentDirID: 7

id 4 - pastaD - parentDirID: null
    id 5 - pastaE - parentDirID: 4
        id 6 - pastaF - parentDirID: 5

Conclusion

When you move a directory, you just change your parent ID .

When you copy a directory, a new directory is created, so you need a new ID. A new directory is also created for each subdirectory, and each of these new subdirectories points their parent ID to the newly created parent ID.

As for the files, new ones will also be created in a copy, so they will also receive new Ids and new parent Ids.

Another modeling option

Your current modeling can be quite difficult to maintain. I would do so:

Diretorios
id - caminho 
 1 - pastaA
 2 - pastaA/pastaB
 3 - pastaA/pastaB/pastaC

Arquivos
id - id_diretorio
 1 - 1
 2 - 1
 3 - 2

It's simpler - it does not have a hierarchy of records, it will save a lot of code and simplify reading of table contents.

    
18.03.2015 / 17:12