[ADD]organization add num_teams
This commit is contained in:
parent
1e70764d63
commit
ddaca5bafc
|
@ -70,7 +70,7 @@ class Organization < Owner
|
||||||
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
|
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,
|
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? }
|
scope :with_visibility, ->(visibility) { joins(:organization_extension).where(organization_extensions: {visibility: visibility}) if visibility.present? }
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
# num_projects :integer default("0")
|
# num_projects :integer default("0")
|
||||||
# num_users :integer default("0")
|
# num_users :integer default("0")
|
||||||
|
# num_teams :integer default("0")
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
@ -25,6 +26,7 @@ class OrganizationExtension < ApplicationRecord
|
||||||
belongs_to :organization
|
belongs_to :organization
|
||||||
has_many :organization_users, foreign_key: :organization_id, primary_key: :organization_id
|
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 :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}
|
enum visibility: {common: 0, limited: 1, privacy: 2}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
# index_projects_on_updated_on (updated_on)
|
# index_projects_on_updated_on (updated_on)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
class Project < ApplicationRecord
|
class Project < ApplicationRecord
|
||||||
include Matchable
|
include Matchable
|
||||||
include Publicable
|
include Publicable
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
class Team < ApplicationRecord
|
class Team < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :organization
|
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_projects, dependent: :destroy
|
||||||
has_many :team_units, dependent: :destroy
|
has_many :team_units, dependent: :destroy
|
||||||
has_many :team_users, dependent: :destroy
|
has_many :team_users, dependent: :destroy
|
||||||
|
|
|
@ -8,5 +8,6 @@ json.visibility organization.visibility
|
||||||
json.max_repo_creation organization.max_repo_creation
|
json.max_repo_creation organization.max_repo_creation
|
||||||
json.num_projects organization.num_projects
|
json.num_projects organization.num_projects
|
||||||
json.num_user organization.num_users
|
json.num_user organization.num_users
|
||||||
|
json.num_teams organization.num_teams
|
||||||
json.avatar_url url_to_avatar(organization)
|
json.avatar_url url_to_avatar(organization)
|
||||||
json.created_at organization.created_on.strftime("%Y-%m-%d")
|
json.created_at organization.created_on.strftime("%Y-%m-%d")
|
|
@ -2,5 +2,12 @@ class AddColumnsToOrganizationExtension < ActiveRecord::Migration[5.2]
|
||||||
def change
|
def change
|
||||||
add_column :organization_extensions, :num_projects, :integer, default: 0
|
add_column :organization_extensions, :num_projects, :integer, default: 0
|
||||||
add_column :organization_extensions, :num_users, :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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue