These are chat archives for edbirmingham/network
NetworkEventmodel -- is that an "Event"?
Program? (perhaps I'm not viewing the correct branch...)
NetworkEvent, and "Event Type" =>
Program, then I would agree with your migration name (above) with a slight modification. I would type ...
rails generate migration AddProgramsToNetworkEvents program:references
class AddProgramsToNetworkEvents < ActiveRecord::Migration def change add_reference :network_events, :program, index: true end end
Programand zero or more
NetworkEvents -- in other words, every
NetworkEventwill have at most 1
Program, and every
Programwill have (potentially) multiple
referencesis some Rails magic. What it will actually do is add a
program_idcolumn to the
network_eventstable as a foreign key, as well as adding an index on that column for that table.)
remove_column, is not "reversible", so you would need to modify the migration further to use
#downblocks, instead of a
#changeblock (if that makes sense).
rails generate migration RemoveEventTypeFromNetworkEvents event_type:stringwould generate the migration you're looking for. It would look something like this...
class RemoveEventTypeFromNetworkEvents < ActiveRecord::Migration def up remove_column :network_events, :event_type end def down add_column :network_events, :event_type, :string end end
rails generate migration RemoveEventTypeFromNetworkEvents event_type:stringproduces (whether or not it creates up/down blocks, or a change block, I mean)
upblock gets run when you run the migration, the
downblock when you roll it back. You can use this to write any ruby code you want in those blocks. For example, you could run a loop through all the current
NetworkEvents in the system in the
upblock, before the
remove_columncall, to grab the current
event_typeand update the record with the proper
program_id. Then, in the
downblock, you can set the proper
event_typefor the record, after the
add_columncall, based on the current
program_idfor the record.
changeblock. I think you're fine, I just wasn't sure. I would trust the
rails generate migrationoutput.
changeblock, as you expect, but it will have trouble if you ever do decide to roll that migration back. Again, I'm not sure. I'd need to experiment.