What are the changes?
Adding NOT NULL constraint on code for charges and fixed charges
The code column on charges and fixed_charges tables will now be required (NOT NULL constraint).
Previously, this column was nullable and only populated on newly created records. Starting from v1.43.0, the database will enforce that every charge and fixed charge has a code value.
The backfill tasks (available since v1.42.0) will:
- Populate
charges.codeusing the associated billable metric’s code - Populate
fixed_charges.codeusing the associated add-on’s code - When duplicates exist within the same plan, a suffix (
_2,_3, etc.) is appended to ensure uniqueness
Why are we doing this?
These changes are made to ensure data integrity and enable the ability to independently update a charge or a fixed charge via the API. Thecode serves as a unique identifier within a plan, which is required by the new dedicated endpoints for managing charges and fixed charges.
What should self-hosted users do?
Cloud users do not need to follow these instructions as the migration will be performed by the Lago Team.
Migration Steps
- Install Lago v1.42.0
- Open a shell (bash) on your API server
- Run the upgrade task:
- Backfill
codeon all charges that have a NULL value - Backfill
codeon all fixed charges that have a NULL value - Process records in batches of 1,000
All resources are processed in background jobs. The task will monitor progress and confirm when all records have been updated.
- Verify that all records have been backfilled:
- Install Lago v1.43.0