[ADD]organization add num_teams

This commit is contained in:
viletyy 2021-02-02 14:21:02 +08:00
parent 1e70764d63
commit ddaca5bafc
6 changed files with 82 additions and 70 deletions

View File

@ -70,7 +70,7 @@ class Organization < Owner
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
delegate :description, :website, :location, :repo_admin_change_team_access,
:visibility, :max_repo_creation, :num_projects, :num_users, to: :organization_extension, allow_nil: true
:visibility, :max_repo_creation, :num_projects, :num_users, :num_teams, to: :organization_extension, allow_nil: true
scope :with_visibility, ->(visibility) { joins(:organization_extension).where(organization_extensions: {visibility: visibility}) if visibility.present? }

View File

@ -14,6 +14,7 @@
# updated_at :datetime not null
# num_projects :integer default("0")
# num_users :integer default("0")
# num_teams :integer default("0")
#
# Indexes
#
@ -25,6 +26,7 @@ class OrganizationExtension < ApplicationRecord
belongs_to :organization
has_many :organization_users, foreign_key: :organization_id, primary_key: :organization_id
has_many :projects, foreign_key: :user_id, primary_key: :organization_id
has_many :teams, foreign_key: :organization_id, primary_key: :organization_id
enum visibility: {common: 0, limited: 1, privacy: 2}

View File

@ -68,6 +68,7 @@
# index_projects_on_updated_on (updated_on)
#
class Project < ApplicationRecord
include Matchable
include Publicable

View File

@ -23,6 +23,7 @@
class Team < ApplicationRecord
belongs_to :organization
belongs_to :organization_extension, foreign_key: :organization_id, primary_key: :organization_id, counter_cache: :num_teams
has_many :team_projects, dependent: :destroy
has_many :team_units, dependent: :destroy
has_many :team_users, dependent: :destroy

View File

@ -8,5 +8,6 @@ json.visibility organization.visibility
json.max_repo_creation organization.max_repo_creation
json.num_projects organization.num_projects
json.num_user organization.num_users
json.num_teams organization.num_teams
json.avatar_url url_to_avatar(organization)
json.created_at organization.created_on.strftime("%Y-%m-%d")

View File

@ -2,5 +2,12 @@ class AddColumnsToOrganizationExtension < ActiveRecord::Migration[5.2]
def change
add_column :organization_extensions, :num_projects, :integer, default: 0
add_column :organization_extensions, :num_users, :integer, default: 0
add_column :organization_extensions, :num_teams, :integer, default: 0
OrganizationExtension.find_each do |e|
OrganizationExtension.reset_counters(e.id, :organization_users)
OrganizationExtension.reset_counters(e.id, :projects)
OrganizationExtension.reset_counters(e.id, :teams)
end
end
end