Files
codeocean/db/migrate/20181119161514_add_user_to_proxy_exercise.rb
Sebastian Serth 6c44ffbd5c Fix missing/incorrect Model specifications in migrations
We need to define the required models within the migration (not below) to work reliably.
2024-07-04 11:02:10 +02:00

19 lines
572 B
Ruby

# frozen_string_literal: true
class AddUserToProxyExercise < ActiveRecord::Migration[5.2]
class Internaluser < ApplicationRecord
end
class ProxyExercise < ApplicationRecord
belongs_to :user, polymorphic: true
end
def change
add_reference :proxy_exercises, :user, polymorphic: true, index: true
add_column :proxy_exercises, :public, :boolean, null: false, default: false
internal_user = InternalUser.find_by(id: 46) || InternalUser.first
ProxyExercise.update(user_id: internal_user&.id || 1, user_type: internal_user.class.name)
end
end