Migratory Shortcuts plugin

Plugin details

ActiveRecord has "magic" fields for implementing some of its amazingly helpful features. Auto timestamping, acts_as_list, acts_as_tree, acts_as_nested_set and so forth. Remembering all these "magic" columns can prove challenging unless you are working with migrations all the time. The other problem is they add noise to table definition sometimes overwhelming critical column(s).

Websitehttp://www.rubybrain.org/articles/4-DRYing-up-migrations-revisited Repositorysvn://rubyforge.org/var/svn/rubybrain/rails/plugins/migratory_shortcuts Author Will Groppe Tags migration LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install svn://rubyforge.org/var/svn/rubybrain/rails/plugins/migratory_shortcuts

Standard migration method

 	create_table :posts do |t|
   		t.column :title, :string, :null => false
   		t.column :post, :text, :null => false
   		t.column :created_at, :datetime
   		t.column :updated_at, :datetime
   		t.column :created_by, :integer, :null => false
   		t.column :updated_by, :integer, :null => false
 	end


With migration extension

	create_table :posts, :with => [:timestamp, :userstamp] do |t|
		t.column :title, :string, :null => false
		t.column :post, :text, :null => false
	end


There also is now a new method for creating link tables that tries to do the right thing when creating links between tables. It takes all the same options as create_table, but expects two tables as parameters.

Methods:

	create_link_table(table_one, table_two, opts= {})
	drop_link_table(table_one, table_two)


Special case: when the first table and the second table start with the same name, the resulting table is named with the second tables name singularized and "_links" appended.

Special Case Example:

  create_link_table(:documents, :document_names) # => document_name_links

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 9 months ago