开发者

Should I use migrations to create folders?

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?


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.


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.


I'd include this in a bootstrap rake task.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜