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_id column: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/5732
  • Start setting billing_account_id in application logic (e.g. when creating a License) https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/5747
  • Use new billing_account relationship instead of customer when account_data_structure feature flag is enabled https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/5798
  • Introduce rake task to backfill billing_account_id for existing License records https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/5967
    • If 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.

Edited Dec 01, 2022 by Etienne Baqué
Assignee Loading
Time tracking Loading