Feb | MAR | SEP
| 21 |
2005 | 2006 | 2007
7 captures 21 Mar 06 - 6 Aug 07 |
| Close Help

edit

## Intelligent Migration Snippets 0.1 for TextMate

on Wednesday, February 22, 2006

This should be working now. I've tested it under a new user account here.

This does requires the syncPeople bundle to be installed to work. That's ok, because you should get the syncPeople on Rails bundle anyways.

When writing database migrations in Ruby on Rails it is common to create a table in the `self.up` method and then drop it in `self.down`. The same goes for adding, removing and renaming columns.

I wrote a Ruby program to insert code into both methods with a single snippet. All the TextMate commands and macros that you need are included.

### See it in action

I think this looks cool in action. Plus I like to show off what what TextMate can do to people who may not use it, or don't have a Mac. It's just over 30 seconds long and weighs in at around 700kb.

Download Demo Video

### Features

There are 3 snippets which are activated by the following tab triggers:

- mcdt: Migration Create and Drop Table
- marc: Migration Add and Remove Column
- mnc: Migration Rename Column

### Installation

Run Quick Install.app to install these commands to your syncPeople on Rails bundle if it exists, and to the default Rails bundle otherwise. (I highly recommend you get the syncPeople bundle if you haven't already.)

Download Intelligent Migration Snippets

This is specific to Rails migrations, but there are probably other uses for something like this. You are free to use and distribute this code.

Posted in mac os x, textmate, rails, hacking | Tags migrations, snippets | 4 comments | no trackbacks

#### Comments

Leave a response

1. nuke edit
   Duane Johnson said about 20 hours later:

   Hi Sami,

   I've downloaded the Intelligent Migration Snippets, and I think I can guess what they're going to do, but unfortunately there's little glitch in the system: the command that the macro calls contains your username hardcoded in to the bundlePath and supportPath arguments.

   I'm trying a few things to see if there's a work around. Until then, let me know if you find anything else!

   Thanks for your research and work in to this, I think it's a great idea!

2. nuke edit
   Sami said about 21 hours later:

   Doh! I forgot about TextMate hardcoding the command paths in the macros. The install script takes care of this now. Sorry about that.

3. nuke edit
   Allan Odgaard said about 22 hours later:

   It shouldn't be necessary to modify the macros at install time.

   Preferebly place the scripts in «target bundle»/Support/bin — this will be in the path when replaying the macro. Note however that while recording the macro, the target bundle is unknown, so at that time, it will not be in the path. But having the scripts, while recording, someplace else, which is in the path should allow graceful recording.

   Alternatively one can use $TM_SUPPORT_PATH in the command to execute. Remember double quotes.

   I would btw suggest putting these things in a bundle of its own, and ship that bundle. That way if you update these commands, only that bundle needs replacing — currently you will have to hunt for the old files in the Rails or syncPeople on Rails bundle, and the latter bundle might overwrite your stuff, if user downloads a new version and double clicks to install.

4. nuke edit
   Sami said 1 day later:

   Ok I think I realized my mistake in recording the macros. I appreciate the feedback. I will post a bundle for this fairly soon, with even more in it.

#### Trackbacks

Use the following link to trackback from your own site:
http://sami.samhuri.net/articles/trackback/23

RSS feed for this post trackback uri

Your name | (leave url/email »)
Your blog |
Your email |
Your message |
Preview comment

# sjs

##

◢◣