Skip to content

Fix voting data migration for AddFollowableCounterCacheToVotings#12350

Merged
alecslupu merged 1 commit intodevelopfrom
fix/votings-migration
Jan 29, 2024
Merged

Fix voting data migration for AddFollowableCounterCacheToVotings#12350
alecslupu merged 1 commit intodevelopfrom
fix/votings-migration

Conversation

@andreslucena
Copy link
Copy Markdown
Member

🎩 What? Why?

While working with an app and disabling the decidim-elections module, I found a data migration that doesn't work. This PR fixes it by following the strategy 3 from #8068 (Define ad-hoc model classe)

Testing

To check the failure:

  1. Comment decidim-elections gem from development_app/Gemfile
  2. Run bundle install
  3. Regenerate and migrate the DB: bin/rails db:drop db:create db:migrate

See the exception:
== 20240125096051 AddFollowableCounterCacheToVotings: migrating ===============
-- add_column(:decidim_votings_votings, :follows_count, :integer, {:null=>false, :default=>0, :index=>true})
-> 0.0011s
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled: (StandardError)

uninitialized constant Decidim::Votings
/home/apereira/Work/decidim/decidim/development_app/db/migrate/20240125096051_add_followable_counter_cache_to_votings.decidim_elections.rb:10:in block (2 levels) in change' /home/apereira/Work/decidim/decidim/development_app/db/migrate/20240125096051_add_followable_counter_cache_to_votings.decidim_elections.rb:9:in block in change'
/home/apereira/Work/decidim/decidim/development_app/db/migrate/20240125096051_add_followable_counter_cache_to_votings.decidim_elections.rb:8:in change' /home/apereira/Work/decidim/decidim/development_app/bin/rails:5:in <top (required)>'
/home/apereira/Work/decidim/decidim/development_app/bin/spring:10:in block in <top (required)>' /home/apereira/Work/decidim/decidim/development_app/bin/spring:7:in <top (required)>'

Caused by:
NameError: uninitialized constant Decidim::Votings (NameError)

    Decidim::Votings::Voting.reset_column_information
                    ^^^^^^^^

/home/apereira/Work/decidim/decidim/development_app/db/migrate/20240125096051_add_followable_counter_cache_to_votings.decidim_elections.rb:10:in block (2 levels) in change' /home/apereira/Work/decidim/decidim/development_app/db/migrate/20240125096051_add_followable_counter_cache_to_votings.decidim_elections.rb:9:in block in change'
/home/apereira/Work/decidim/decidim/development_app/db/migrate/20240125096051_add_followable_counter_cache_to_votings.decidim_elections.rb:8:in change' /home/apereira/Work/decidim/decidim/development_app/bin/rails:5:in <top (required)>'
/home/apereira/Work/decidim/decidim/development_app/bin/spring:10:in block in <top (required)>' /home/apereira/Work/decidim/decidim/development_app/bin/spring:7:in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

To fix it:

  1. Apply this patch
  2. Remove the migration rm development_app/db/migrate/*_add_followable_counter_cache_to_votings.decidim_elections.rb
  3. Copy the new migration bin/rails decidim:update
  4. Migrate bin/rails db:migrate

♥️ Thank you!

@andreslucena andreslucena added module: elections type: fix PRs that implement a fix for a bug labels Jan 29, 2024
Copy link
Copy Markdown
Contributor

@alecslupu alecslupu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reset the DB, got the error,
reacreated the app using this PR, and worked well.

@alecslupu alecslupu merged commit 0b0106c into develop Jan 29, 2024
@alecslupu alecslupu deleted the fix/votings-migration branch January 29, 2024 15:09
entantoencuanto added a commit that referenced this pull request Feb 1, 2024
* develop:
  Remove elections module (#12366)
  Fix flaky for questionnaire drag and drop question (#12367)
  Redesign: datepicker (#11768)
  Patch participatory spaces factories (#12341)
  Upgrade chromedriver to v120+ (#12351)
  Fix bug in welcome notifications when the organization has weird characters (#12326)
  Have only one h1 in the admin pages (#12340)
  Fix voting data migration for AddFollowableCounterCacheToVotings (#12350)
  New Crowdin updates (#12282)
  Fix broken links in debates index (#12343)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: elections type: fix PRs that implement a fix for a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants