For those who come by this by the Redmine thread I created: I tried to post the solution there as well, but the SPAM filter would not let me follow-up on the thread. It is probably because there was no intermediate response (*tear*).
It took a bit of time, but I figured it out. (I made a test instance of Redmine so as to not mess anything up with our production instance, so these values are default and should work for anybody trying to do this.)
A short synopsis of the process:
- Find the internal ID of the project you wish to add the files to.
- Determine file statistics.
- Insert file into database.
There is in fact no database validation going on, so even (2) is optional. As such, I won't go over how to get that information. (There are ample resources even on this site as to how to get this information.) The rest, however, requires a tiny bit of knowledge of how Redmine has its databases set up.
To start this, connect to your production MySQL database. (This is usually, if not always, redmine_production
. You can list all MySQL databases with the command SHOW DATABASES;
.)
Now, find the ID of your project you wish to add the file to. In the columns listing above, this will be inserted as container_id
.
mysql> SELECT * FROM projects; +----+----------------+-------------+----------+-----------+-----------+---------------------+---------------------+----------------+--------+------+------+ | id | name | description | homepage | is_public | parent_id | created_on | updated_on | identifier | status | lft | rgt | +----+----------------+-------------+----------+-----------+-----------+---------------------+---------------------+----------------+--------+------+------+ | 1 | git-helloworld | NULL | | 1 | NULL | 2012-01-01 13:00:00 | 2012-01-01 13:00:00 | git-helloworld | 1 | 1 | 2 | | 2 | bzr-helloworld | NULL | | 1 | NULL | 2012-01-01 13:00:00 | 2012-01-01 13:00:00 | bzr-helloworld | 1 | 1 | 2 | | 3 | hg-helloworld | NULL | | 1 | NULL | 2012-01-01 13:00:00 | 2012-01-01 13:00:00 | hg-helloworld | 1 | 1 | 2 | | 4 | svn-helloworld | NULL | | 1 | NULL | 2012-01-01 13:00:00 | 2012-01-01 13:00:00 | svn-helloworld | 1 | 1 | 2 | +----+----------------+-------------+----------+-----------+-----------+---------------------+---------------------+----------------+--------+------+------+ 4 rows in set (0.00 sec)
In this example, we want to add the files to git-helloworld
, so our ID is 1
. So, to add a file to the database, we will execute the SQL command:
INSERT INTO attachments (container_id, container_type, filename, disk_filename, digest) VALUES ( 1, 'Project', 'Some File Name', 'file-name-on-disk', '0123456789abcdef');
A few notes about these fields:
container_id
: The ID of the project you wish to include the file incontainer_type
: The type of container this is; for this purpose, it is alwaysProject
filename
: The string to display as the file namedisk_filename
: The actual path of the file, relative to/var/www/redmine/files/
digest
: A string representing the MD5 checksum of the file.
Some not required, but recommended fields:
filesize
: The size of the file as an integer. I assume this is meant to be in bytes or kilobytes, but I don't know if it matters.author_id
: A user to associate the file with. For my purposes, I'm going to useadmin
. Note that you can get a full list of Redmine users withSELECT * FROM users;
.description
: A file description. (This is the same optional description used in the interface.)content_type
: I would assume this is a MIME content type.created_on
: The date this file was created on.
For the explicit types of all of these, refer to the columns listing in the original post.
Next, ensure that the path in disk_filename
actually exists relative to your redmine/files/
directory. (Note this means that you can actually organize it!) You don't have to do this, but you will obviously get a 404 if the file isn't there.
After that, you should be good to go!