Skip to content
Permalink
Browse files

FIX: replace model usage with SQL query

Follow-up to b500ef7
  • Loading branch information...
ZogStriP committed Aug 13, 2019
1 parent 961213b commit c628166bb4b3c22d664da6c03760caa53a613a4a
Showing with 3 additions and 3 deletions.
  1. +3 −3 plugins/poll/db/post_migrate/20180820080623_migrate_polls_data.rb
@@ -85,7 +85,7 @@ def up
end

r.polls.values.each do |poll|
name = poll["name"].presence || "poll"
name = escape(poll["name"].presence || "poll")
type = POLL_TYPES[(poll["type"].presence || "")[/(regular|multiple|number)/, 1] || "regular"]
status = poll["status"] == "open" ? 0 : 1
visibility = poll["public"] == "true" ? 1 : 0
@@ -95,7 +95,7 @@ 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))
next if DB.query_single("SELECT COUNT(*) FROM polls WHERE post_id = ? AND name = ? LIMIT 1", r.post_id, name).first > 0

poll_id = execute(<<~SQL
INSERT INTO polls (
@@ -113,7 +113,7 @@ def up
updated_at
) VALUES (
#{r.post_id},
'#{escape(name)}',
'#{name}',
#{type},
#{status},
#{visibility},

0 comments on commit c628166

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