Sha256: 45649ad45bee99f93cced12f4f8349849a03f501c7fc28b477a2b9fee5cc7483

Contents?: true

Size: 1.07 KB

Versions: 49

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

class MakeCommentsHandleI18n < ActiveRecord::Migration[5.2]
  class User < ApplicationRecord
    self.table_name = :decidim_users
  end

  class Comment < ApplicationRecord
    self.table_name = :decidim_comments_comments
  end

  class Organization < ApplicationRecord
    self.table_name = :decidim_organizations
  end

  def change
    add_column :decidim_comments_comments, :new_body, :jsonb

    User.reset_column_information
    Comment.reset_column_information
    Organization.reset_column_information

    Comment.find_each do |comment|
      locale, org_id = User.where(id: comment.decidim_author_id).pick(:locale, :decidim_organization_id)
      locale = locale.presence || Organization.find(org_id).default_locale

      comment.new_body = {
        locale => comment.body
      }

      comment.save!
    end

    remove_column :decidim_comments_comments, :body
    rename_column :decidim_comments_comments, :new_body, :body

    User.reset_column_information
    Comment.reset_column_information
    Organization.reset_column_information
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
decidim-comments-0.30.0.rc3 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.30.0.rc2 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.30.0.rc1 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.29.2 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.28.5 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.29.1 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.28.4 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.27.9 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.29.0 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.28.3 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.27.8 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.29.0.rc4 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.29.0.rc3 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.29.0.rc2 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.29.0.rc1 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.28.2 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.27.7 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.28.1 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.27.6 db/migrate/20200706123136_make_comments_handle_i18n.rb
decidim-comments-0.26.10 db/migrate/20200706123136_make_comments_handle_i18n.rb