Migrate Rails: Add One Column to Multiple Tables

Is there any special syntax for adding a timestamp column to multiple tables?

+4
source share
1 answer

Not special purpose syntax, but you can certainly iterate over an array of table names and perform the same migration steps for each one.

class AddTimeStampsToABandC < ActiveRecord::Migration AFFECTED_TABLES = [:table_a, :table_b, :table_c] def self.up AFFECTED_TABLES.each do |t| add_timestamps(t) end end def self.down AFFECTED_TABLES.each do |t| remove_timestamps(t) end end end 
+7
source

Source: https://habr.com/ru/post/1346158/


All Articles