Skip to content
Snippets Groups Projects
Verified Commit 563a3eb9 authored by Vijay Hawoldar's avatar Vijay Hawoldar Committed by GitLab
Browse files

Adds GitlabSubscriptions::SeatAssignment model

In order to track member activity and seat usage within a namespace
hierarchy, we are adding a new table, subscription_seat_assignments

Changelog: added
EE: true
parent f8fd6cfd
No related branches found
No related tags found
2 merge requests!170053Security patch upgrade alert: Only expose to admins 17-4,!164799Adds GitlabSubscriptions::SeatAssignment model
Showing with 138 additions and 0 deletions
---
table_name: subscription_seat_assignments
description: Stores seat assignment information and activity within a namespace
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/164799
milestone: '17.5'
feature_categories:
- seat_cost_management
classes:
- GitlabSubscriptions::SeatAssignment
gitlab_schema: gitlab_main_cell
allow_cross_foreign_keys:
- gitlab_main_clusterwide
sharding_key:
namespace_id: namespaces
# frozen_string_literal: true
class CreateSubscriptionSeatAssignments < Gitlab::Database::Migration[2.2]
milestone '17.5'
UNIQUE_INDEX_NAME = 'uniq_idx_subscription_seat_assignments_on_namespace_and_user'
def change
create_table :subscription_seat_assignments do |t| # rubocop:disable Migration/EnsureFactoryForTable -- https://gitlab.com/gitlab-org/gitlab/-/issues/468630
t.bigint :namespace_id, null: false
t.bigint :user_id, null: false
t.datetime_with_timezone :last_activity_on, null: true
t.timestamps_with_timezone null: false
t.index [:namespace_id, :user_id], unique: true, name: UNIQUE_INDEX_NAME
t.index :user_id
end
end
end
# frozen_string_literal: true
class AddForeignKeyNamespaceIdOnSubscriptionSeatAssignments < Gitlab::Database::Migration[2.2]
milestone '17.5'
disable_ddl_transaction!
def up
add_concurrent_foreign_key :subscription_seat_assignments, :namespaces, column: :namespace_id, on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :subscription_seat_assignments, column: :namespace_id
end
end
end
# frozen_string_literal: true
class AddForeignKeyUserIdOnSubscriptionSeatAssignments < Gitlab::Database::Migration[2.2]
milestone '17.5'
disable_ddl_transaction!
def up
add_concurrent_foreign_key :subscription_seat_assignments, :users, column: :user_id, on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :subscription_seat_assignments, column: :user_id
end
end
end
6279f239c4710913bbad810dfed38933697f2522a6e0757ab0ee2b4767b63ddf
\ No newline at end of file
3342f53b0c51ea82b295899ba4ffb39fd4ccfe58bfae4f92a9ff9d4e125c0df4
\ No newline at end of file
43d2c4ab67b518fff0f1a9483570ae6543f607a668a18efa1752721859969cfb
\ No newline at end of file
......@@ -18764,6 +18764,24 @@ CREATE SEQUENCE subscription_add_ons_id_seq
 
ALTER SEQUENCE subscription_add_ons_id_seq OWNED BY subscription_add_ons.id;
 
CREATE TABLE subscription_seat_assignments (
id bigint NOT NULL,
namespace_id bigint NOT NULL,
user_id bigint NOT NULL,
last_activity_on timestamp with time zone,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
);
CREATE SEQUENCE subscription_seat_assignments_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE subscription_seat_assignments_id_seq OWNED BY subscription_seat_assignments.id;
CREATE TABLE subscription_user_add_on_assignments (
id bigint NOT NULL,
add_on_purchase_id bigint NOT NULL,
......@@ -22559,6 +22577,8 @@ ALTER TABLE ONLY subscription_add_on_purchases ALTER COLUMN id SET DEFAULT nextv
 
ALTER TABLE ONLY subscription_add_ons ALTER COLUMN id SET DEFAULT nextval('subscription_add_ons_id_seq'::regclass);
 
ALTER TABLE ONLY subscription_seat_assignments ALTER COLUMN id SET DEFAULT nextval('subscription_seat_assignments_id_seq'::regclass);
ALTER TABLE ONLY subscription_user_add_on_assignments ALTER COLUMN id SET DEFAULT nextval('subscription_user_add_on_assignments_id_seq'::regclass);
 
ALTER TABLE ONLY subscriptions ALTER COLUMN id SET DEFAULT nextval('subscriptions_id_seq'::regclass);
......@@ -25271,6 +25291,9 @@ ALTER TABLE ONLY subscription_add_on_purchases
ALTER TABLE ONLY subscription_add_ons
ADD CONSTRAINT subscription_add_ons_pkey PRIMARY KEY (id);
 
ALTER TABLE ONLY subscription_seat_assignments
ADD CONSTRAINT subscription_seat_assignments_pkey PRIMARY KEY (id);
ALTER TABLE ONLY subscription_user_add_on_assignments
ADD CONSTRAINT subscription_user_add_on_assignments_pkey PRIMARY KEY (id);
 
......@@ -30616,6 +30639,8 @@ CREATE UNIQUE INDEX index_subscription_add_ons_on_name ON subscription_add_ons U
 
CREATE INDEX index_subscription_addon_purchases_on_expires_on ON subscription_add_on_purchases USING btree (expires_on);
 
CREATE INDEX index_subscription_seat_assignments_on_user_id ON subscription_seat_assignments USING btree (user_id);
CREATE INDEX index_subscription_user_add_on_assignments_on_organization_id ON subscription_user_add_on_assignments USING btree (organization_id);
 
CREATE INDEX index_subscription_user_add_on_assignments_on_user_id ON subscription_user_add_on_assignments USING btree (user_id);
......@@ -31396,6 +31421,8 @@ CREATE UNIQUE INDEX uniq_idx_streaming_destination_id_and_namespace_id ON audit_
 
CREATE UNIQUE INDEX uniq_idx_streaming_group_destination_id_and_namespace_id ON audit_events_streaming_group_namespace_filters USING btree (external_streaming_destination_id, namespace_id);
 
CREATE UNIQUE INDEX uniq_idx_subscription_seat_assignments_on_namespace_and_user ON subscription_seat_assignments USING btree (namespace_id, user_id);
CREATE UNIQUE INDEX uniq_idx_user_add_on_assignments_on_add_on_purchase_and_user ON subscription_user_add_on_assignments USING btree (add_on_purchase_id, user_id);
 
CREATE UNIQUE INDEX uniq_pkgs_deb_grp_architectures_on_distribution_id_and_name ON packages_debian_group_architectures USING btree (distribution_id, name);
......@@ -33461,6 +33488,9 @@ ALTER TABLE ONLY dast_sites
ALTER TABLE ONLY project_saved_replies
ADD CONSTRAINT fk_0ace76afbb FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE NOT VALID;
 
ALTER TABLE ONLY subscription_seat_assignments
ADD CONSTRAINT fk_0b6bc63773 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY approval_group_rules_protected_branches
ADD CONSTRAINT fk_0b85e6c388 FOREIGN KEY (protected_branch_id) REFERENCES protected_branches(id) ON DELETE CASCADE;
 
......@@ -34205,6 +34235,9 @@ ALTER TABLE ONLY work_item_dates_sources
ALTER TABLE ONLY bulk_import_exports
ADD CONSTRAINT fk_8c6f33cebe FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY subscription_seat_assignments
ADD CONSTRAINT fk_8d214f4142 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY raw_usage_data
ADD CONSTRAINT fk_8e21125854 FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE;
 
# frozen_string_literal: true
module GitlabSubscriptions
class SeatAssignment < ApplicationRecord
belongs_to :namespace, optional: false
belongs_to :user, optional: false
validates :namespace_id, uniqueness: { scope: :user_id }
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :gitlab_subscription_seat_assignment, class: 'GitlabSubscriptions::SeatAssignment' do
namespace
user
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSubscriptions::SeatAssignment, feature_category: :seat_cost_management do
subject { build(:gitlab_subscription_seat_assignment) }
describe 'associations' do
it { is_expected.to belong_to(:namespace).required }
it { is_expected.to belong_to(:user).required }
end
describe 'validations' do
it { is_expected.to validate_uniqueness_of(:namespace_id).scoped_to(:user_id) }
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment