mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-06 14:53:13 +08:00
35 lines
1 KiB
Ruby
35 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class CreateDiscourseVotingVotes < ActiveRecord::Migration[6.0]
|
|
def up
|
|
create_table :discourse_voting_votes do |t|
|
|
t.integer :topic_id
|
|
t.integer :user_id
|
|
t.boolean :archive, default: false
|
|
t.timestamps
|
|
end
|
|
add_index :discourse_voting_votes, %i[user_id topic_id], unique: true
|
|
|
|
DB.exec <<~SQL
|
|
INSERT INTO discourse_voting_votes(topic_id, user_id, archive, created_at, updated_at)
|
|
SELECT value::integer, user_id, 'false', created_at, updated_at
|
|
FROM user_custom_fields
|
|
WHERE name = 'votes'
|
|
AND value <> ''
|
|
ON CONFLICT(user_id, topic_id) DO NOTHING
|
|
SQL
|
|
|
|
DB.exec <<~SQL
|
|
INSERT INTO discourse_voting_votes(topic_id, user_id, archive, created_at, updated_at)
|
|
SELECT value::integer, user_id, 'true', created_at, updated_at
|
|
FROM user_custom_fields
|
|
WHERE name = 'votes_archive'
|
|
AND value <> ''
|
|
ON CONFLICT(user_id, topic_id) DO NOTHING
|
|
SQL
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|