juntagrico / juntagrico-billing

GNU Lesser General Public License v3.0
2 stars 3 forks source link

Migrations for juntagrico 1.4 #15

Closed samuel-iseli closed 3 years ago

samuel-iseli commented 3 years ago

juntagrico release 1.4 removes the extrasubscription entities und makes extrasubscriptions normal subscription parts (see juntagrico/juntagrico#258).

In juntagrico_billing the items on a bill currently reference subscription- and extrasubscription-types. As extrasubscription-types are removed with juntagrico 1.4, we need to change this referencing and migrate existing bill items.

As the referencing of subscription- and extrasubscription-types was a poor design decision anyway, we will change the bill items to refence subscription-parts instead of types, which make a lot of code easier.

Bill items

Bill Items get a new ForeignKeyField subscription_part. There are now only 2 kinds of BillItems:

  1. BillItem referencing a subscription part, e.g. subscription or extra subscriptions
  2. BillItem referencing a custom item type, e.g. some manual part of a bill

Existing BillItems referencing subscription types are migrated by looking for a subscription part for the same member. This is possible as long as there is still only 1 billed subscription (not extra subscription) per member.

Existing BillItems referencing extrasubscription are migrated to subscription parts by looking up (member, name) pairs).

Extra subscription accounts

The ExtraSubscriptionCategoryAccount existed to be able to assign a booking account to extrasubscriptions based on their category. These entities are migrated to SubscriptionTypeAccount entities as the extrasubscription newly is a normal subscription.

data migration

The migration in juntagrico_billing comes in 3 steps:

The migration must be performed manually because it is not possible to enforce a certain sequence of migrations steps spanning multiple apps.

To perform the migration, the following steps have to be performed:

migrations squashed

Due to the manual steps, theses migrations cannot be left in the source code, as they cannot be automatically applied (eg when running unit tests). I squashed all the migrations up to and including 0012_post_1_4 into a new migration called 0001_squashed_0012_post_1_4 and deleted all the old migrations modules.