Skip to content

Commit

Permalink
Don't migrate data, just schema
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolgual committed May 13, 2021
1 parent 8fb4279 commit ba8e4e2
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 120 deletions.
24 changes: 12 additions & 12 deletions db/migrate/20210217110107_add_scope_id_to_census_authorizations.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
class AddScopeIdToCensusAuthorizations < ActiveRecord::Migration[5.2]
def up
scopes = Decidim::Scope.all
scopes_by_name = scopes.map{ |scope| [scope.name["ca"], scope.id] }.to_h

Decidim::Authorization.where(name: "census_authorization_handler").find_each do |auth|
scope_name = cleanup_scope_name(auth.metadata["scope"])
scope_id = scopes_by_name[scope_name]

raise "ERROR: #{scope_name} scope not found for auth #{auth.id}" unless scope_id rescue byebug
auth.metadata["scope"] = scope_name
auth.metadata["scope_id"] = scope_id
auth.save
end
# scopes = Decidim::Scope.all
# scopes_by_name = scopes.map{ |scope| [scope.name["ca"], scope.id] }.to_h
#
# Decidim::Authorization.where(name: "census_authorization_handler").find_each do |auth|
# scope_name = cleanup_scope_name(auth.metadata["scope"])
# scope_id = scopes_by_name[scope_name]
#
# raise "ERROR: #{scope_name} scope not found for auth #{auth.id}" unless scope_id rescue byebug
# auth.metadata["scope"] = scope_name
# auth.metadata["scope_id"] = scope_id
# auth.save
# end
end

def down; end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class InvalidateAllSessionsForDeletedUsers < ActiveRecord::Migration[5.2]
def up
Decidim::User.reset_column_information

Decidim::User.where.not(deleted_at: nil).find_each(&:invalidate_all_sessions!)
# Decidim::User.where.not(deleted_at: nil).find_each(&:invalidate_all_sessions!)
end

def down; end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

class EncryptAuthorizationMetadatas < ActiveRecord::Migration[5.2]
def up
Decidim::Authorization.find_each do |auth|
# Re-setting these values will internally convert the hash values to
# encypted values
p "#{auth.name}: #{auth.id}"
auth.update!(
metadata: auth.metadata,
verification_metadata: auth.verification_metadata
)
end
# Decidim::Authorization.find_each do |auth|
# # Re-setting these values will internally convert the hash values to
# # encypted values
# p "#{auth.name}: #{auth.id}"
# auth.update!(
# metadata: auth.metadata,
# verification_metadata: auth.verification_metadata
# )
# end
end

def down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ class AddAllowPublicAccessToStaticPages < ActiveRecord::Migration[5.2]
def change
add_column :decidim_static_pages, :allow_public_access, :boolean, null: false, default: false

reversible do |direction|
direction.up do
# rubocop:disable Rails/SkipsModelValidations
Decidim::StaticPage.where(slug: "terms-and-conditions").update_all(
allow_public_access: true
)
# rubocop:enable Rails/SkipsModelValidations
end
end
# reversible do |direction|
# direction.up do
# # rubocop:disable Rails/SkipsModelValidations
# Decidim::StaticPage.where(slug: "terms-and-conditions").update_all(
# allow_public_access: true
# )
# # rubocop:enable Rails/SkipsModelValidations
# end
# end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
class RenameNameColumnToTitleInDecidimParticipatoryProcessGroups < ActiveRecord::Migration[5.2]
def up
rename_column :decidim_participatory_process_groups, :name, :title
PaperTrail::Version.where(item_type: "Decidim::ParticipatoryProcessGroup").each do |version|
# rubocop:disable Rails/SkipsModelValidations
version.update_attribute(:object_changes, version.object_changes.gsub(/^name:/, "title:")) if version.object_changes.present?
# rubocop:enable Rails/SkipsModelValidations

next unless version.object.present? && version.object.has_key?("name")

object = version.object
object["title"] = object.delete("name")

# rubocop:disable Rails/SkipsModelValidations
version.update_attribute(:object, object)
# rubocop:enable Rails/SkipsModelValidations
end
# PaperTrail::Version.where(item_type: "Decidim::ParticipatoryProcessGroup").each do |version|
# # rubocop:disable Rails/SkipsModelValidations
# version.update_attribute(:object_changes, version.object_changes.gsub(/^name:/, "title:")) if version.object_changes.present?
# # rubocop:enable Rails/SkipsModelValidations
#
# next unless version.object.present? && version.object.has_key?("name")
#
# object = version.object
# object["title"] = object.delete("name")
#
# # rubocop:disable Rails/SkipsModelValidations
# version.update_attribute(:object, object)
# # rubocop:enable Rails/SkipsModelValidations
# end
end

def down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def change
add_column :decidim_meetings_meetings, :registration_type, :string, null: false, default: "registration_disabled"
add_column :decidim_meetings_meetings, :registration_url, :string

Meetings.reset_column_information
Meetings.find_each do |meeting|
meeting.registration_type = "on_this_platform" if meeting.decidim_author_type == "Decidim::Organization"
meeting.save(validate: false)
end
# Meetings.reset_column_information
# Meetings.find_each do |meeting|
# meeting.registration_type = "on_this_platform" if meeting.decidim_author_type == "Decidim::Organization"
# meeting.save(validate: false)
# end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

class FixAnsweredProposalsAfterCopy < ActiveRecord::Migration[5.2]
def change
proposals_after_copy = Decidim::ResourceLink.where(from_type: "Decidim::Proposals::Proposal").pluck(:from_id)

result = Decidim::Proposals::Proposal.where.not(state_published_at: nil).where(state: nil, id: proposals_after_copy)

result.find_each do |proposal|
proposal.state_published_at = nil
proposal.save!
end
# proposals_after_copy = Decidim::ResourceLink.where(from_type: "Decidim::Proposals::Proposal").pluck(:from_id)
#
# result = Decidim::Proposals::Proposal.where.not(state_published_at: nil).where(state: nil, id: proposals_after_copy)
#
# result.find_each do |proposal|
# proposal.state_published_at = nil
# proposal.save!
# end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class AddFollowableCounterCacheToUsers < ActiveRecord::Migration[5.2]
def change
add_column :decidim_users, :follows_count, :integer, null: false, default: 0, index: true

reversible do |dir|
dir.up do
Decidim::User.reset_column_information
Decidim::User.find_each do |record|
record.class.reset_counters(record.id, :follows)
end
end
end
# reversible do |dir|
# dir.up do
# Decidim::User.reset_column_information
# Decidim::User.find_each do |record|
# record.class.reset_counters(record.id, :follows)
# end
# end
# end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class AddFollowableCounterCacheToParticipatoryProcesses < ActiveRecord::Migratio
def change
add_column :decidim_participatory_processes, :follows_count, :integer, null: false, default: 0, index: true

reversible do |dir|
dir.up do
Decidim::ParticipatoryProcess.reset_column_information
Decidim::ParticipatoryProcess.find_each do |record|
record.class.reset_counters(record.id, :follows)
end
end
end
# reversible do |dir|
# dir.up do
# Decidim::ParticipatoryProcess.reset_column_information
# Decidim::ParticipatoryProcess.find_each do |record|
# record.class.reset_counters(record.id, :follows)
# end
# end
# end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class AddFollowableCounterCacheToAssemblies < ActiveRecord::Migration[5.2]
def change
add_column :decidim_assemblies, :follows_count, :integer, null: false, default: 0, index: true

reversible do |dir|
dir.up do
Decidim::Assembly.reset_column_information
Decidim::Assembly.find_each do |record|
record.class.reset_counters(record.id, :follows)
end
end
end
# reversible do |dir|
# dir.up do
# Decidim::Assembly.reset_column_information
# Decidim::Assembly.find_each do |record|
# record.class.reset_counters(record.id, :follows)
# end
# end
# end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class AddFollowableCounterCacheToMeetings < ActiveRecord::Migration[5.2]
def change
add_column :decidim_meetings_meetings, :follows_count, :integer, null: false, default: 0, index: true

reversible do |dir|
dir.up do
Decidim::Meetings::Meeting.reset_column_information
Decidim::Meetings::Meeting.find_each do |record|
record.class.reset_counters(record.id, :follows)
end
end
end
# reversible do |dir|
# dir.up do
# Decidim::Meetings::Meeting.reset_column_information
# Decidim::Meetings::Meeting.find_each do |record|
# record.class.reset_counters(record.id, :follows)
# end
# end
# end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

class FixCountersForCopiedProposals < ActiveRecord::Migration[5.2]
def up
copies_ids = Decidim::ResourceLink.where(
name: "copied_from_component",
from_type: "Decidim::Proposals::Proposal",
to_type: "Decidim::Proposals::Proposal"
).pluck(:to_id)

Decidim::Proposals::Proposal.where(id: copies_ids).find_each do |record|
record.class.reset_counters(record.id, :follows)
record.update_comments_count
end
# copies_ids = Decidim::ResourceLink.where(
# name: "copied_from_component",
# from_type: "Decidim::Proposals::Proposal",
# to_type: "Decidim::Proposals::Proposal"
# ).pluck(:to_id)
#
# Decidim::Proposals::Proposal.where(id: copies_ids).find_each do |record|
# record.class.reset_counters(record.id, :follows)
# record.update_comments_count
# end
end

def down; end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class AddFollowableCounterCacheToBlogs < ActiveRecord::Migration[5.2]
def change
add_column :decidim_blogs_posts, :follows_count, :integer, null: false, default: 0, index: true

reversible do |dir|
dir.up do
Decidim::Blogs::Post.reset_column_information
Decidim::Blogs::Post.find_each do |record|
record.class.reset_counters(record.id, :follows)
end
end
end
# reversible do |dir|
# dir.up do
# Decidim::Blogs::Post.reset_column_information
# Decidim::Blogs::Post.find_each do |record|
# record.class.reset_counters(record.id, :follows)
# end
# end
# end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class AddFollowableCounterCacheToInitiatives < ActiveRecord::Migration[5.2]
def change
add_column :decidim_initiatives, :follows_count, :integer, null: false, default: 0, index: true

reversible do |dir|
dir.up do
Decidim::Initiative.reset_column_information
Decidim::Initiative.find_each do |record|
record.class.reset_counters(record.id, :follows)
end
end
end
# reversible do |dir|
# dir.up do
# Decidim::Initiative.reset_column_information
# Decidim::Initiative.find_each do |record|
# record.class.reset_counters(record.id, :follows)
# end
# end
# end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Area < ApplicationRecord
def change
add_column :decidim_navigation_maps_blueprint_areas, :area_id, :string

Area.find_each do |area|
area.area_id = area.id
area.save!
end
# Area.find_each do |area|
# area.area_id = area.id
# area.save!
# end
end
end

0 comments on commit ba8e4e2

Please sign in to comment.