Sha256: 3ca6c2e92ad1e07fd8a3e34edfd86bc6c6ce2a5b977b50ac91bd5b2b3439e53e

Contents?: true

Size: 1.33 KB

Versions: 18

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

class MoveSignatureTypeToInitativeType < ActiveRecord::Migration[5.2]
  class InitiativesType < ApplicationRecord
    self.table_name = :decidim_initiatives_types
  end

  def change
    if !ActiveRecord::Base.connection.table_exists?("decidim_initiatives_types")
      Rails.logger.info "Skipping migration since there's no InitiativesType table"
      return
    elsif InitiativesType.count.positive?
      raise "You need to edit this migration to continue"
    end

    # This flag says when mixed and face-to-face voting methods
    # are allowed. If set to false, only online voting will be
    # allowed
    # face_to_face_voting_allowed = true

    add_column :decidim_initiatives_types, :signature_type, :integer, null: false, default: 0

    InitiativesType.reset_column_information

    Decidim::Initiatives::InitiativesType.find_each do |type|
      type.signature_type = if type.online_signature_enabled && face_to_face_voting_allowed
                              :any
                            elsif type.online_signature_enabled && !face_to_face_voting_allowed
                              :online
                            else
                              :offline
                            end
      type.save!
    end

    remove_column :decidim_initiatives_types, :online_signature_enabled
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
decidim-initiatives-0.24.3 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.23.6 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.24.2 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.23.5 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.24.1 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.24.0 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.24.0.rc2 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.23.4 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.24.0.rc1 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.23.3 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.23.2 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.23.1 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.23.1.rc1 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.23.0 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.22.0 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.21.0 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.20.1 db/migrate/20191002082220_move_signature_type_to_initative_type.rb
decidim-initiatives-0.20.0 db/migrate/20191002082220_move_signature_type_to_initative_type.rb