Subversion is great! There, I said it. But how can we collaborate on one and the same project when some files (such as useruploads) are not versioned and are scattered amongst the developers their filesystems/machines?
How we use SVN
At work, my colleague Tijs and I started off with a new project this week. As me and my colleagues do with all projects, we each have a local instance of the website running on our own machine (viz. local Apache & local MySQL) under a fake url
http://projectname.local/ (long live Apache vhosts and Windows hosts file manipulation). By this we can develop features separately and eventually commit the changes to the repository when finished. As we update regularly the new features are rolled out onto each dev machine per update. Only data that isn’t versioned are the database and the user uploads.
Unscattering the data
As Tijs is the main lead on the database design for this specific project (and needs to update/extend the structure every now and then) we decided that I’d connect to his database, making sure that both of us are using the latest DB schema and same testdata instead of exchanging
.sql dumps every now and then.
Only problem we ran into is that some of the modules we are writing require uploads: When I add a new entry (through my local instance of the site) the data indeed gets nicely stored into Tijs’ database, yet the files get stored on my local hard disk (in the
files/ subfolder of the website). Time to start fiddling around in order to get all data onto Tijs his Mac, yet let me continue developing locally.
The plan we rolled out consists of three steps:
- Enabling me to surf to Tijs’ instance of the project
- Redirecting all HTTP requests to uploaded files on my machine to Tijs’ machine
- Moving all uploaded files from my machine to Tijs’ machine, so that the HTTP requests from 2. actually resolve to a valid (viz. non-404) location.
1. Enabling me to surf to Tijs’ instance of the project
This one is actually very simple: Tijs configures a vhost named
projectname.tijs on his Apache and I edit my hosts file so that
projectname.tijs points to his IP-address.
2. Redirecting all HTTP requests to uploaded files on my machine to Tijs’ machine
In order to redirect all requests to files located in the
files/ subfolder from my machine to Tijs’ machine, we’re using mod_rewrite. One extra line in my local .htaccess file and I’m good to go:
[code]RewriteRule ^files/(.*)$ http://projectname.tijs/userfiles/$1 [R,NC,L][/code]
That little rule above – for example – will redirect a request to
http://projectname.tijs/files/artists/22.jpg yet keep requests to
http://projectname.local/anythingbutfiles/ pointing to my local instance.
3. Moving all uploaded files from my machine to Tijs’ machine
First of all, Tijs shared the folder where his instance of the project is running and I mounted it as Network Drive to which I (quite obviously) assigned
Then I decided knocked up a little batch file which copies all the files from my machine to Tijs’ machine by using the xcopy command, allowing me to recursively copy data via the
[code]xcopy files T:\default_www\files\ /E /C[/code]
Now, as I don’t want to copy all files each time to Tijs’ machine, I extended the batch file with a second line to delete all my local files (recursively and without confirmation) so that when no new files were adding, nothing gets copied (as the folders are empty).
[code]del files\*.* /S /Q[/code]
All one has to do now is to run that bat file every now and then or – if you’re quite lazy – push it into the Windows Task Scheduler to call it let’s say every 5 minutes.
That’s it, we’re done here!