Sha256: 121ec98d7db584b5378ef5a5c98a1bf7a0419a61edbcdb3e5e6d1eac93fd80f5

Contents?: true

Size: 1.2 KB

Versions: 68

Compression:

Stored size: 1.2 KB

Contents

class AddMissingConstraints < ActiveRecord::Migration
  def change
    BitPlayer::ParticipantStatus.all.each do |s|
      s.destroy! if s.participant.nil?
    end
    Group.all.each do |g|
      g.update!(arm_id: nil) if g.arm.nil?
    end

    reversible do |dir|
      dir.up do
        execute <<-SQL
          ALTER TABLE bit_player_participant_statuses
            ADD CONSTRAINT fk_statuses_participants
            FOREIGN KEY (participant_id)
            REFERENCES participants(id)
        SQL
        execute <<-SQL
          ALTER TABLE groups
            ADD CONSTRAINT fk_groups_arms
            FOREIGN KEY (arm_id)
            REFERENCES arms(id)
        SQL
      end

      dir.down do
        execute <<-SQL
          ALTER TABLE bit_player_participant_statuses
            DROP CONSTRAINT IF EXISTS fk_statuses_participants
        SQL
        execute <<-SQL
          ALTER TABLE groups
            DROP CONSTRAINT IF EXISTS fk_groups_arms
        SQL
      end
    end

    change_column_null :arms, :has_woz, false
    change_column_null :emotional_ratings, :rating, false
    change_column_null :moods, :rating, false
    change_column_null :participant_login_events, :participant_id, false
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.9 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.22.8 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.22.7 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.22.6 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.22.5 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.22.4 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.22.2 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.22.1 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.22.0 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.21.2 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.21.1 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.21.0 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.20.1 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.19.9 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.19.8 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.19.7 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.19.6 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.19.5 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.19.4 db/migrate/20150210161100_add_missing_constraints.rb
think_feel_do_engine-3.19.3 db/migrate/20150210161100_add_missing_constraints.rb