Sha256: 0294cde6282edd6add04174fd73731a026669af726b5d045580f7a94f70912ae
Contents?: true
Size: 1.16 KB
Versions: 2
Compression:
Stored size: 1.16 KB
Contents
class CreateActivityTypes < ActiveRecord::Migration def self.up create_table( :activity_types) do |t| t.string :label t.timestamps end # Create invoice_activity_types for habtm create_table( :invoices_activity_types, :id => false ) do |t| t.integer :invoice_id, :activity_type_id end add_index :invoices_activity_types, [:invoice_id, :activity_type_id] activity_types = [] say_with_time "Populating initial activities ..." do # Now create the initial entries: activity_models_path = BRISKBILLS_ROOT+'/app/models/activity' Find.find(activity_models_path) do |a| activity_types << ActivityType.create( :label => $1.capitalize ) if /^#{activity_models_path}\/([^\/]+)\.rb$/.match a end end # Adjust all the pre-existing invoices to reflect the new activity_types habtm the way they should say_with_time "Associating existing invoices with activity types" do Invoice.find(:all).each { |inv| activity_types.each{ |a| inv.activity_types << a } } end end def self.down drop_table :activity_types drop_table :invoices_activity_types end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
brisk-bills-0.8.2 | db/migrate/018_create_activity_types.rb |
brisk-bills-0.8.1 | db/migrate/018_create_activity_types.rb |