Sha256: f4ca8a3bd8da6c079444acf74d05574c253d3d5cec27f1a226f8a0344a7dc0cc

Contents?: true

Size: 1.3 KB

Versions: 75

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

class AddScopesForAllInitiativeTypes < ActiveRecord::Migration[5.1]
  class Scope < ApplicationRecord
    self.table_name = :decidim_scopes
  end

  class Organization < ApplicationRecord
    self.table_name = :decidim_organizations

    has_many :scopes, foreign_key: "decidim_organization_id", class_name: "Scope"
  end

  class InitiativesType < ApplicationRecord
    self.table_name = :decidim_initiatives_types

    belongs_to :organization,
               foreign_key: "decidim_organization_id",
               class_name: "Organization"
  end

  class InitiativesTypeScope < ApplicationRecord
    self.table_name = :decidim_initiatives_type_scopes
  end

  def up
    # This migrantion intent is simply to keep seed data at staging
    # environment consistent with the underlying data model. It is
    # not relevant for production environments.
    Organization.find_each do |organization|
      InitiativesType.where(organization: organization).find_each do |type|
        organization.scopes.each do |scope|
          InitiativesTypeScope.create(
            decidim_initiatives_types_id: type.id,
            decidim_scopes_id: scope.id,
            supports_required: 1000
          )
        end
      end
    end
  end

  def down
    Decidim::InitiativesTypeScope.destroy_all
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
decidim-initiatives-0.27.9 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.8 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.7 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.6 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.26.10 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.26.9 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.5 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.26.8 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.4 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.3 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.26.7 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.26.5 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.2 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.1 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.26.4 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.0 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.26.3 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.0.rc2 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.27.0.rc1 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb
decidim-initiatives-0.26.2 db/migrate/20171017091734_add_scopes_for_all_initiative_types.rb