mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 21:44:31 +08:00
5c524ea8a4
Previously we used custom fields to denote a user was anonymous, this was risky in that custom fields are prone to race conditions and are not properly dedicated, missing constraints and so on. The new table `anonymous_users` is properly protected. There is only one possible shadow account per user, which is enforced using a constraint. Every anonymous user will have a unique row in the new table.
24 lines
641 B
Ruby
24 lines
641 B
Ruby
# frozen_string_literal: true
|
|
|
|
class AnonymousUser < ActiveRecord::Base
|
|
belongs_to :user
|
|
belongs_to :master_user, class_name: 'User'
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: anonymous_users
|
|
#
|
|
# id :bigint not null, primary key
|
|
# user_id :integer not null
|
|
# master_user_id :integer not null
|
|
# active :boolean not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_anonymous_users_on_master_user_id (master_user_id) UNIQUE WHERE active
|
|
# index_anonymous_users_on_user_id (user_id) UNIQUE
|
|
#
|