podemos-info/participa2

View on GitHub
db/migrate/20180509103163_make_attachments_polymorphic.decidim_participatory_processes.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

# This migration comes from decidim_participatory_processes (originally 20170123134023)

class MakeAttachmentsPolymorphic < ActiveRecord::Migration[5.0]
  def change
    transaction do
      remove_index :decidim_participatory_process_attachments, name: "index_decidim_processes_attachments_on_decidim_process_id"
      rename_table :decidim_participatory_process_attachments, :decidim_attachments

      add_column :decidim_attachments, :attachable_type, :string
      execute("UPDATE decidim_attachments SET attachable_type = 'Decidim::ParticipatoryProcess'")

      rename_column :decidim_attachments, :decidim_participatory_process_id, :attachable_id
      add_index :decidim_attachments, [:attachable_id, :attachable_type]

      change_column_null(:decidim_attachments, :attachable_id, false)
      change_column_null(:decidim_attachments, :attachable_type, false)
    end
  end
end