Add GitlabSubscriptions::SystemDefined::AddOn fixed items model
What does this MR do and why?
Part of customers-gitlab-com#15784 (closed) (phase B2 of gitlab-org#19981).
Adds GitlabSubscriptions::SystemDefined::AddOn, an ActiveRecord::FixedItemsModel with the same items as the
GitlabSubscriptions::AddOn enum (same pattern as SystemDefined::Plan). Item ids equal the enum values, which
are the subscription_add_on_uid values we already write. Id 2 is skipped because the enum tombstoned
product_analytics in 19.4 (!250892 (merged)).
Nothing reads it yet. !249922 (closed) points the add-on readers and writers at it and targets this branch until this merges. A parity spec keeps the items in sync with the AR enum until customers-gitlab-com#15788 drops the table.
No SQL in here. Danger flags the where( in names_for_uids as a database change, but that is the
FixedItemsModel in-memory filter, so this needs no database review.
What each method mirrors
Every method here matches something on the AR model, so !249922 (closed) swaps the constant at each call site and changes nothing else.
| Here | On GitlabSubscriptions::AddOn today |
|---|---|
ITEMS ids, names, descriptions |
enum :name values and .descriptions |
DUO_ADD_ONS, SEAT_ASSIGNABLE_DUO_ADD_ONS |
same constants |
.names |
enum .names (HashWithIndifferentAccess, name => value) |
.uids_for_names |
.uids_for_names |
.names_for_uids |
none; copied from SystemDefined::Plan |
code_suggestions? and the other name predicates |
enum-generated predicates |
#seat_assignable? |
same method |
Not ported: find_or_create_by_name and the duo_add_ons / active scopes. They need the table, and the AR
model stays for the subscription_add_on_id dual-write until #15788.
How to set up and validate locally
a = GitlabSubscriptions::SystemDefined::AddOn
a.names == GitlabSubscriptions::AddOn.names # => true
a.uids_for_names(%w[code_suggestions duo_enterprise nope]) # => [1, 3]
a.names_for_uids([1, 2, 3]) # => ["code_suggestions", "duo_enterprise"]
a.find_by!(name: "duo_enterprise").seat_assignable? # => true
a.find(4).duo_amazon_q? # => trueMR acceptance checklist
Evaluate this MR against the MR acceptance checklist.