forked from RedHatInsights/insights-rbac
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the workspace model PK to be a uuid and drop the explicit uuid…
… column This would start a new convention with the v2 APIs and models in order to have consistent, clear naming, particularly when it comes to FK references. We currently have the `uuid` field as the self-referencial FK column on the `Workspace` model. More details around the impetus for changing the naming around IDs can be found in RedHatInsights#1257. These changes offer an alternate approach, since we have no data in stage/production, where we no longer use the `uuid` as the `lookup_field` in Django, but rather use a `uuid` as the `id` format. The rationale for not doing this, and having an explicit `uuid` was primarily for having sequential integers as the PK/FK relations. However, UUID7 is a time-ordered UUID, eliminating index issues and solving the need for having distributed ID values across our services. We're using `uuid-utils` [1] which is a compliant implementation using Rust's UUID library. There's also an open proposal [2,3] to add it to Python's standard library. This updates the model, view and serializer. In order to move the `id` from int to uuid, we need two migrations: - one to move the current `id` column, and the `parent` column (because of the FK ref) as well as making the current `uuid` column the PK - a second to then rename the `uuid` column to `id` and add the `parent` FK ref/column back [1] https://github.com/aminalaee/uuid-utils [2] python/cpython#89083 [3] https://discuss.python.org/t/add-uuid7-in-uuid-module-in-standard-library/44390
- Loading branch information
1 parent
592b9c2
commit 0d95c01
Showing
8 changed files
with
440 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
rbac/management/migrations/0057_remove_workspace_id_remove_workspace_parent_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 4.2.16 on 2024-10-24 20:26 | ||
|
||
from django.db import migrations, models | ||
import uuid_utils.compat | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("management", "0056_alter_tenantmapping_tenant"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="workspace", | ||
name="id", | ||
), | ||
migrations.RemoveField( | ||
model_name="workspace", | ||
name="parent", | ||
), | ||
migrations.AlterField( | ||
model_name="workspace", | ||
name="uuid", | ||
field=models.UUIDField( | ||
default=uuid_utils.compat.uuid7, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
unique=True, | ||
), | ||
), | ||
] |
30 changes: 30 additions & 0 deletions
30
rbac/management/migrations/0058_rename_uuid_workspace_id_workspace_parent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 4.2.16 on 2024-10-24 20:27 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("management", "0057_remove_workspace_id_remove_workspace_parent_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name="workspace", | ||
old_name="uuid", | ||
new_name="id", | ||
), | ||
migrations.AddField( | ||
model_name="workspace", | ||
name="parent", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="children", | ||
to="management.workspace", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters