Skip to content
Permalink
Browse files

Poll migration is not idempotent (#7964)

The migration script is not idempotent due to database constrains on the
poll related objects, namely:

polls: index_polls_on_post_id_and_name (post_id,name) UNIQUE
poll_options: index_poll_options_on_poll_id_and_digest  (poll_id,digest) UNIQUE
poll_votes:  index_poll_votes_on_poll_id_and_poll_option_id_and_user_id  (poll_id,poll_option_id,user_id) UNIQUE

This change skips a particular poll migration if it's already found on
the db.
  • Loading branch information...
eduardopoleo authored and ZogStriP committed Aug 8, 2019
1 parent 7c83d2e commit b500ef77d78f76e34216f1367e58482a8c957270
Showing with 2 additions and 0 deletions.
  1. +2 −0 plugins/poll/db/post_migrate/20180820080623_migrate_polls_data.rb
@@ -95,6 +95,8 @@ def up
step = poll["step"].to_i.clamp(0, max)
anonymous_voters = poll["anonymous_voters"].to_i.clamp(0, PG_INTEGER_MAX)

next if Poll.exists?(post_id: r.post_id, name: escape(name))

This comment has been minimized.

Copy link
@tgxworld

tgxworld Aug 11, 2019

Contributor

Should this be done in SQL instead?

This comment has been minimized.

Copy link
@eviltrout

eviltrout Aug 12, 2019

Member

Yes since it's in a migration this should be done in SQL. cc @ZogStriP

This comment has been minimized.

Copy link
@discoursereviewbot

discoursereviewbot Aug 13, 2019

SamSaffron posted:

Yes this kind of things tend to be timebombs.


poll_id = execute(<<~SQL
INSERT INTO polls (
post_id,

1 comment on commit b500ef7

Please sign in to comment.
You can’t perform that action at this time.