Add billing_account_id to License
Problem
The License model currently has an association with an individual Customer (to be renamed User) via foreign key customer_id. This model really should be associated with a BillingAccount instead of an individual Customer. Most data that references Customer should be pulled directly from the BillingAccount, or from the Sold To Contact associated with the BillingAccount.
Proposal
With the new data structure for BillingAccount and BillingAccountMembership, the License model should be updated to be associated with an BillingAccount instead of a Customer. The full migration will need to be done in steps, spread across multiple issues and MRs.
For this issue, we will focus on getting to compatibility mode where customer_id continues to be set, but the billing_account_id will also be set. In this issue, the following should be covered:
-
Add billing_account_idcolumn: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/5732 -
Start setting billing_account_idin application logic (e.g. when creating aLicense) https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/5747 -
Use new billing_accountrelationship instead ofcustomerwhenaccount_data_structurefeature flag is enabled https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/5798 -
Introduce rake task to backfill billing_account_idfor existingLicenserecords https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/5967If it's easier, this could be added to the rake task from #4798 (closed). Or it could be a standalone task.
Result
billing_account_id will be populated similar to how customer_id is set currently. customer_id will continue to be populated to ensure compatibility and allow us to revert if needed. When the feature flag is enabled, the new billing_account_id will be used instead of customer_id.