Normalize for domain_id, i.e. ensure User and Project entities have the domain_id as a first class attribute.
Both User and Project (as well as Group) entities are owned by a domain, which is implemented as each having a domain_id foreign key in their sql representation that points back to the respective domain in the domain table. This domain_id attribute should also be required (i.e. not nullable)
Adding a non_nullable foreign key attribute to a table with existing data causes a few problems since not all DB engines support the ability to either control the triggering of integrity constraints or the ability to modify columns after they are created.
To get round the above inconsistencies, two versions of the upgrade/downgrade functions are supplied, one for those engines that support dropping columns, and one for those that don’t. For the latter we are forced to do table copy AND control the triggering of integrity constraints.
Adds an enabled column to the endpoint table.
The enabled value for the endpoint table was stored in the extra column as part of a JSON string.
To upgrade, the enabled column is added with a default value of true, then we check all the extra JSON for disabled and set the value to false for those.
Downgrade is essentially the opposite – we update the JSON with "enabled": false for any endpoints that are disabled and drop the enabled column.
Relax the uniqueness of description column in region table.
The region table has a dedicated column for the region description. This column originally was not nullable and had to be unique. So if a user wanted to create a region without sending a description in the request, they would experience an SQL error because the description column can’t be null for a region. This means that every region had to have a unique description.
To upgrade, we are going to transfer all the data from the existing region table to a temporary table, drop the original region table, and then finally rename the temporary table to the correct name.
There is no downgrade path as the original migration has been fixed to not include the unique constraint on description column.
Adds an enabled column to the service table.
The enabled value for the service table was stored in the extra column as part of a JSON string.
To upgrade, the enabled column is added with a default value of true, then we check all the extra JSON for disabled and set the value to false for those.
Downgrade is essentially the opposite – we update the JSON with "enabled": false for any services that are disabled and drop the enabled column.