Sha256: 04d5c000c068bdf90cc236bfcd077f239e9066846afad57774039ff208a723d8

Contents?: true

Size: 1.5 KB

Versions: 44

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

class MergeMeetingsMinutesIntoMeetingsTable < ActiveRecord::Migration[6.0]
  class Minutes < ApplicationRecord
    self.table_name = "decidim_meetings_minutes"

    belongs_to :meeting, foreign_key: "decidim_meeting_id", class_name: "Meeting"
  end

  class Meeting < ApplicationRecord
    self.table_name = "decidim_meetings_meetings"
  end

  def up
    add_column :decidim_meetings_meetings, :minutes_description, :jsonb
    add_column :decidim_meetings_meetings, :video_url, :string
    add_column :decidim_meetings_meetings, :audio_url, :string
    add_column :decidim_meetings_meetings, :minutes_visible, :boolean

    Minutes.find_each do |minutes|
      minutes.meeting.update!(
        minutes_description: minutes.description,
        video_url: minutes.video_url,
        audio_url: minutes.audio_url,
        minutes_visible: minutes.visible
      )
    end
  end

  def down
    Meeting.find_each do |meeting|
      next if meeting.video_url.blank? && meeting.audio_url.blank?

      Minutes.find_or_create_by!(
        decidim_meeting_id: meeting.id,
        description: meeting.minutes_description,
        video_url: meeting.video_url,
        audio_url: meeting.audio_url,
        visible: meeting.minutes_visible
      )
    end

    remove_column :decidim_meetings_meetings, :minutes_description
    remove_column :decidim_meetings_meetings, :video_url
    remove_column :decidim_meetings_meetings, :audio_url
    remove_column :decidim_meetings_meetings, :minutes_visible
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-meetings-0.29.1 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.28.4 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.27.9 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.29.0 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.28.3 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.27.8 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.29.0.rc4 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.29.0.rc3 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.29.0.rc2 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.29.0.rc1 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.28.2 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.27.7 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.28.1 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.27.6 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.26.10 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.26.9 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.28.0 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.27.5 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.28.0.rc5 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb
decidim-meetings-0.28.0.rc4 db/migrate/20210506180226_merge_meetings_minutes_into_meetings_table.rb