Wayback Machine
MAY JUN JUL
Previous capture 15 Next capture
2005 2006 2007
31 captures
3 Mar 06 - 21 Mar 09
sparklines
Close Help

Some TextMate snippets for Rails Migrations

on Saturday, February 18, 2006

My arsenal of snippets and macros in TextMate is building as I read through the rails canon, Agile Web Development... I'm only 150 pages in so I haven't had to add much so far because I started with the bundle found on the rails wiki. The main ones so far are for migrations.

Initially I wrote a snippet for adding a table and one for dropping a table, but I don't want to write it twice every time! If I'm adding a table in up then I probably want to drop it in down.

What I did was create one snippet that writes both lines, then it's just a matter of cut & paste to get it in down. The drop_table line should be inserted in the correct method, but that doesn't seem possible. I hope I'm wrong!

Scope should be source.ruby.rails and the triggers I use are above the snippets.

 

mcdt: Migration Create and Drop Table

create_table "${1:table}" do |t|
    $0
end
${2:drop_table "$1"}

mcc: Migration Create Column

t.column "${1:title}", :${2:string}

marc: Migration Add and Remove Column

add_column "${1:table}", "${2:column}", :${3:string}
${4:remove_column "$1", "$2"}

I realize this might not be for everyone, so here are my original 4 snippets that do the work of marc and mcdt.

 

mct: Migration Create Table

create_table "${1:table}" do |t|
    $0
end

mdt: Migration Drop Table

drop_table "${1:table}"

mac: Migration Add Column

add_column "${1:table}", "${2:column}", :${3:string}

mrc: Migration Rremove Column

remove_column "${1:table}", "${2:column}"

I'll be adding more snippets and macros. There should be a central place where the rails bundle can be improved and extended. Maybe there is...

Posted in , ,  | Tags , ,  | 6 comments | no trackbacks

Comments

  1. Avatar Duane Johnson said about 8 hours later:

    Hi Sami,

    This looks great! I agree, we should have some sort of central place for these things, and preferably something that's not under the management of the core Rails team as they have too much to worry about already.

    Would you mind if I steal your snippets and put them in the syncPeople on Rails bundle?

  2. Avatar Sami said about 20 hours later:

    Not at all. I'm excited about this bundle you've got. Keep up the great work.

  3. Avatar Duane Johnson said 1 day later:

    Just added the snippets, Sami. I'll try to make a release tonight. Great work, and keep it coming!

    P.S. I tried several ways to get the combo-snippets to put the pieces inside the right functions but failed. We'll see tomorrow if Allan (creator of TextMate) has any ideas.

  4. Avatar dvdplm said 31 days later:

    Need some help here...

    Installed the syncPeople bundle. It's in ~/Library/Application Support/TextMate/Bundles/Rails.tmbundle/

    Inside there is a Support/bin folder with the scripts needed for the macros/snippets, but typing "mcdt\t" gives an error: "/bin/bash: line 1: intelligent_migration_snippet.rb: command not found". Not really sure where TextMate look, but not in the right place. If I put the absolute path to the rb script in the "command" everything works.

    So, do I need some environment vars set? Some other config magic? An installation note would be great...

    :-/

  5. Avatar Sami Samhuri said 32 days later:

    I can't reproduce that behaviour here. TextMate should search ~/Library/Application Support/TextMate/Bundles/Rails.tmbundle/Support/bin automatically.

    On a new user account here I installed TM, then installed the syncPeople bundle and it just worked. Perhaps some cruft is affecting things. If possible I suggest starting with a fresh Rails.tmbundle from syncPeople. If that fails maybe starting with a fresh ~/Library/Application Support/TextMate folder will help.

  6. Avatar Fernando Reig Matthies said 62 days later:

    I get the same error when using mcdt\t>

    /Users/freig/Library/Application Support/TextMate/Bundles/Rails.tmbundle/Support/bin/intelligent_migration_snippet.rb:54:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileinsert_migration' from /Users/freig/Library/Application Support/TextMate/Bundles/Rails.tmbundle/Support/bin/intelligent_migration_snippet.rb:75

Trackbacks

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

(leave url/email »)

   Preview comment