views:

111

answers:

5

I created a feature that requires two folders to work correctly. These folders didn't existed in the rails project so I had to create them. Now I need to push this functionality so that the other developers can use it as well.

What do you think is the best practice:

  1. Create the folders locally and leave a note somewhere explaining that these folders needs to be created

  2. Create a migration that will create these folders

  3. Create the folders if they don't exist on execution

So what are the best practices regarding this?

A: 

I'll add them to the repository. Maybe if it holds temporary data I'll ignore the contents.

aurelian
I can't really do this because it depends on the environment. Sorry I didn't say that in the question
marcgg
+3  A: 

I would think that as part of the dev builds there must be rake tasks that get invoked to do certain activities; it would be appropriate to either include such activity in a rake tasks where it fits most appropriately. It should check for folders and if it doesn't exists; just create them. Migrations for creating folder is really not the right way I guess.

Priyank
+2  A: 

I'd include this in a bootstrap rake task.

dylanfm
You lost me there, I've never done this, do you have a link explaining what you mean?
marcgg
It would involved creating a rake task in /lib/tasks for setting up the environment. Let's say you make a task so that when you run `rake yourapp:bootstrap` it executes some code that creates these folders for you.
dylanfm
thanks for the clarification
marcgg
+2  A: 

This is a good question.

For me I would put the folder creation in the migration if and only if the folder was required as part of that migration. So for instance you were adding or updating the table dealing with attachments (such as with attachment_fu etc), then I would consider putting the directory creation/deletion in there.

However creating directories is an environment specific thing (different on Windows vs *nix etc), especially where permissions are involved. Therefore it would make sense to go where these issues are handled in an environment-abstracted way. Perhaps in the deployment script (if using Capistrano) or as other people have suggested in a rake task.

Daemin
this makes a lot of sense, the more I think of it the more I think this is the right way to go
marcgg
+6  A: 

Two choices

1. Put them under version control.

When the developers next check out the folders will get created. How you add them to VC depends on the nature of the tool you're using but many tools require that the directories contain a file (possibly hidden).

That works great if the folders are in the source tree. You also have the potential on a Unix-like os to soft-link from within the source tree to a well known location outside of the source tree. Depending on the VC system (we use Mercurial), you can make the soft link a versioned item.


2. Create them as your process starts

If you're going to do this, you might as well go the extra mile and make their location a configurable option. On start up, read the config file, make the folders and continue.

Chris McCauley
This is what we do. It only works if they're in the directory tree under version control (e.g. not in /tmp or something), but if they are it's great. We use placeholder.txt as the obligatory file to force the existence of the directory.
edebill
If using git you can just add a blank .gitignore file to the directory you want to keep.
Daemin
@Deamin, does that actually store the directory or just not complain that it doesn't know what it is? I ask because Mercurial would just ignore the directory, not checking it in or out.
Chris McCauley