From 5f201fa084ea183e251127936b4b3aabc8ad88ac Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Fri, 13 Dec 2019 17:33:53 +0800 Subject: [PATCH] ADD platform column to users table --- app/models/user.rb | 6 ++++++ db/migrate/20191212110933_add_platform_to_users.rb | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 db/migrate/20191212110933_add_platform_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index eb3ece0a4..0a16b7aa3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -30,6 +30,11 @@ class User < ApplicationRecord LOGIN_CHARS = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z).freeze + # educoder: 来自Educoder平台 + # trustie: 来自Trustie平台 + # forge: 平台本身注册的用户 + enum platform: [:forge, :educoder, :trustie] + belongs_to :laboratory, optional: true has_one :user_extension, dependent: :destroy @@ -168,6 +173,7 @@ class User < ApplicationRecord # # validations # + validates :platform, inclusion: { in: %w(forge educoder trustie) } validates_presence_of :login, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }, case_sensitive: false validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, case_sensitive: false diff --git a/db/migrate/20191212110933_add_platform_to_users.rb b/db/migrate/20191212110933_add_platform_to_users.rb new file mode 100644 index 000000000..6bb4615a4 --- /dev/null +++ b/db/migrate/20191212110933_add_platform_to_users.rb @@ -0,0 +1,5 @@ +class AddPlatformToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :platform, :string, default: 0 + end +end