tracks/db/migrate/002_add_user_id.rb

22 lines
672 B
Ruby
Raw Permalink Normal View History

2019-05-13 18:42:57 +02:00
class AddUserId < ActiveRecord::Migration[5.2]
class Project < ActiveRecord::Base; end
class Context < ActiveRecord::Base; end
class Todo < ActiveRecord::Base; end
def self.up
add_column :contexts, :user_id, :integer, :default => 1
add_column :projects, :user_id, :integer, :default => 1
add_column :todos, :user_id, :integer, :default => 1
2013-09-13 16:44:59 +02:00
Context.all.each { |context| context.user_id = 1 }
Project.all.each { |project| project.user_id = 1 }
Todo.all.each { |todo| todo.user_id = 1 }
end
def self.down
remove_column :contexts, :user_id
remove_column :projects, :user_id
remove_column :todos, :user_id
end
end