Commit f218e2da authored by Mark Chao's avatar Mark Chao

Add seats related columns for easier data analysis

Don't keep history for these new columns since they can be calculated
parent f9087286
---
title: Add seats related columns for easier data analysis
merge_request: 40470
author:
type: other
# frozen_string_literal: true
class AddSeatsCurrentlyInUseInGitlabSubscriptions < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
add_column :gitlab_subscriptions, :seats_in_use, :integer, default: 0, null: false
add_column :gitlab_subscriptions, :seats_owed, :integer, default: 0, null: false
end
end
def down
with_lock_retries do
remove_column :gitlab_subscriptions, :seats_in_use
remove_column :gitlab_subscriptions, :seats_owed
end
end
end
bdcfd7dbccc73d6e2754d67bf099cc2dd2b919e4125cec47e853ff91911cc82e
\ No newline at end of file
...@@ -12133,7 +12133,9 @@ CREATE TABLE public.gitlab_subscriptions ( ...@@ -12133,7 +12133,9 @@ CREATE TABLE public.gitlab_subscriptions (
seats integer DEFAULT 0, seats integer DEFAULT 0,
trial boolean DEFAULT false, trial boolean DEFAULT false,
trial_starts_on date, trial_starts_on date,
auto_renew boolean auto_renew boolean,
seats_in_use integer DEFAULT 0 NOT NULL,
seats_owed integer DEFAULT 0 NOT NULL
); );
CREATE SEQUENCE public.gitlab_subscriptions_id_seq CREATE SEQUENCE public.gitlab_subscriptions_id_seq
......
...@@ -99,7 +99,7 @@ class GitlabSubscription < ApplicationRecord ...@@ -99,7 +99,7 @@ class GitlabSubscription < ApplicationRecord
attrs['gitlab_subscription_id'] = self.id attrs['gitlab_subscription_id'] = self.id
attrs['change_type'] = change_type attrs['change_type'] = change_type
omitted_attrs = %w(id created_at updated_at) omitted_attrs = %w(id created_at updated_at seats_in_use seats_owed)
GitlabSubscriptionHistory.create(attrs.except(*omitted_attrs)) GitlabSubscriptionHistory.create(attrs.except(*omitted_attrs))
end end
......
...@@ -324,7 +324,7 @@ RSpec.describe GitlabSubscription do ...@@ -324,7 +324,7 @@ RSpec.describe GitlabSubscription do
end end
it 'gitlab_subscription columns are contained in gitlab_subscription_history columns' do it 'gitlab_subscription columns are contained in gitlab_subscription_history columns' do
diff_attrs = %w(updated_at) diff_attrs = %w(updated_at seats_in_use seats_owed)
expect(described_class.attribute_names - GitlabSubscriptionHistory.attribute_names).to eq(diff_attrs) expect(described_class.attribute_names - GitlabSubscriptionHistory.attribute_names).to eq(diff_attrs)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment