2

I am trying to understand the Drupal database schema because I need to access the database via MySQL by another system and I do not have access to the original Drupal developer of the site nor do I know Drupal well at this point (I did work with it 8 years ago) and it will be much easier to access with MySQL than to set up a server to have to host a PHP-based API or similar.

file_usage

In the file_usage table there are two (2) field module and type and using a GROUP BY query this is what I get:

module | type
-------|-------
 file  | node
 imce  | file
 user  | user

So it is pretty obvious that module means that entry was added by either the file, imce or user modules, right?

My questions are:

  1. What does node, file and user mean in this context?
  2. Is file/node effectively the same as imce/file, or is it something different?
  3. Does user/user mean it is a file associated with the user?
  4. Further file_usage has an id column; can I assume:
    1. That nid for file/node and imce/file?
    2. And uid is for user/user?
    3. Or something else?

NOTE: I do not have access to the working Drupal system, I only have access to the database.

2

So it is pretty obvious that module means that entry was added by either the file, imce or user modules, right?

Right, it's just the name of the module that added the record.

What does node, file and user mean in this context?

They're arbitrary strings used by each module to identify the "type" of file usage the current record relates to. A single module might keep to track of files in several different contexts, so this is important.

Is file/node effectively the same as imce/file, or is it something different?

They're different. file/node is for usage of files attached to a file field on a content type; imce/file is for tracking files uploaded and (potentially) inserted into a WYSIWYG.

Does user/user mean it is a file associated with the user?

It doesn't have to necessarily, just because it's called user/user, but in this case yes, it does.

Further file_usage has an id column; can I assume:...

Yes, that assumption is correct. The ID can relate to anything at all though, not just an entity that lives inside Drupal, it's up to the module using the table to be able to resolve which object/item is being referred to from the data in that table.

3
  • file/node is for usage of files attached to a file field on a content type; imce/file is for tracking files uploaded and (potentially) inserted into a WYSIWYG. Thanks. Still unclear how to handle. IOW, what does id represent for imce/file? The ID can relate to anything at all though I only trying to tie the data I have, not handle future potentials where the id could be used differently. So does it seem I just have files associated with node, with user and then what imce files are related to? – MikeSchinkel Apr 26 '16 at 9:00
  • IMCE doesn't need to tie that record up with anything else, so it just uses the file ID (fid). So it relates to the file in file_managed. You'll find that happens reasonably often, the id column is mandatory so if the data doesn't need to relate to something else, relating it to the file itself again is fine – Clive Apr 26 '16 at 9:07
  • Ah, no wonder I was confused. I was looking for specific order when there was none. :-) Thank you! – MikeSchinkel Apr 26 '16 at 9:23
2

So it is pretty obvious that module means that entry was added by either the file, imce or user modules, right?

Yes. The module column tells you what module is using this instance of the file.

What does node, file and user mean in this context?

This is the name of the entity that is using this is instance of the file. So if it is node, then the file is attached to a node, if it is file then it is a standalone file entity, if it is user it attached to a user (typically a profile image) and so on.

Is file/node effectively the same as imce/file, or is it something different?

Different. file/node are a file attached to a node (main Drupal content). imce/file is managed by the imce module as standalone files.

Each entity using the file has its own primary key identifying instance, The id column identifies this instance. For instance the id associated with imce/file identifies the specific file entity (and just reuses the file fid for the id column), while the id associated with the file/node identifies the node entity.

Does user/user mean it is a file associated with the user?

It tells you that the file was added to Drupal's manged files by the core user module, and is attached to a userentity.

Further file_usage has an id column; can I assume:
1. That nid for file/node and imce/file?

It is nid for file/node, but fid for imce/file.

  1. And uid is for user/user?

Yes.

2
  • Thanks. What does id relate to in case of imce/file? – MikeSchinkel Apr 26 '16 at 9:04
  • For instance imce/file identifies the specific imce entity using this file. IMCE doesn't have entities as it happens, it just uses the file ID again for the ID column – Clive Apr 26 '16 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.