Add billing_account_id to Order

Problem

The Order model currently has an association with an individual Customer (to be renamed User) via foreign key customer_id. This relationship is problematic for many reasons and should be associated with a BillingAccount instead.

Proposal

With the new data structure for BillingAccount and BillingAccountMembership, the Order model should be updated to be associated with a 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/5750
  • Start setting billing_account_id in application logic (e.g. when creating/updating a Order) - https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/5770
  • 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/5874
  • Introduce rake task to backfill billing_account_id for existing Order 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