diff --git a/app/models/anonymous_block.rb b/app/models/anonymous_block.rb index accaa7e7..02a14498 100644 --- a/app/models/anonymous_block.rb +++ b/app/models/anonymous_block.rb @@ -5,6 +5,7 @@ require "digest" class AnonymousBlock < ApplicationRecord belongs_to :user, optional: true belongs_to :question, optional: true + belongs_to :target_user, class_name: "User", optional: true def self.get_identifier(ip) Digest::SHA2.new(512).hexdigest(Rails.application.secret_key_base + ip) diff --git a/db/migrate/20221227002012_add_target_user_to_anonymous_blocks.rb b/db/migrate/20221227002012_add_target_user_to_anonymous_blocks.rb new file mode 100644 index 00000000..23c3af72 --- /dev/null +++ b/db/migrate/20221227002012_add_target_user_to_anonymous_blocks.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddTargetUserToAnonymousBlocks < ActiveRecord::Migration[6.1] + def change + add_reference :anonymous_blocks, :target_user, null: true, foreign_key: { to_table: :users } + end +end diff --git a/db/schema.rb b/db/schema.rb index f871d86d..20bd3d6e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_11_16_201723) do +ActiveRecord::Schema.define(version: 2022_12_27_002012) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -28,13 +28,15 @@ ActiveRecord::Schema.define(version: 2022_11_16_201723) do end create_table "anonymous_blocks", force: :cascade do |t| + t.bigint "user_id" t.string "identifier" + t.bigint "question_id", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.bigint "user_id" - t.bigint "question_id" + t.bigint "target_user_id" t.index ["identifier"], name: "index_anonymous_blocks_on_identifier" t.index ["question_id"], name: "index_anonymous_blocks_on_question_id" + t.index ["target_user_id"], name: "index_anonymous_blocks_on_target_user_id" t.index ["user_id"], name: "index_anonymous_blocks_on_user_id" end