diff --git a/test/globalsearch/test_indexer.py b/test/globalsearch/test_indexer.py index 0f4e5034..79dfd7a7 100644 --- a/test/globalsearch/test_indexer.py +++ b/test/globalsearch/test_indexer.py @@ -11,9 +11,7 @@ def _initialize(client, models): for model, index in models: - client.create_index( - uid=index, options={"name": model.__name__, "primaryKey": "id"} - ) + client.create_index(uid=index, options={"primaryKey": "id"}) def test_index_model(): diff --git a/zoo/entities/migrations/0002_auto_20211007_1000.py b/zoo/entities/migrations/0002_allow_null_product_owner_on_group.py similarity index 100% rename from zoo/entities/migrations/0002_auto_20211007_1000.py rename to zoo/entities/migrations/0002_allow_null_product_owner_on_group.py diff --git a/zoo/entities/migrations/0003_allow_blank_on_group.py b/zoo/entities/migrations/0003_allow_blank_on_group.py new file mode 100644 index 00000000..39075ade --- /dev/null +++ b/zoo/entities/migrations/0003_allow_blank_on_group.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.19 on 2021-10-13 09:52 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("entities", "0002_allow_null_product_owner_on_group"), + ] + + operations = [ + migrations.AlterField( + model_name="entity", + name="group", + field=models.OneToOneField( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="entities.Group", + ), + ), + ] diff --git a/zoo/entities/migrations/0004_import_objects_to_entity_model.py b/zoo/entities/migrations/0004_import_objects_to_entity_model.py new file mode 100644 index 00000000..e9c24766 --- /dev/null +++ b/zoo/entities/migrations/0004_import_objects_to_entity_model.py @@ -0,0 +1,85 @@ +import structlog +from django.db import migrations + +from zoo.entities.enums import Kind + +log = structlog.get_logger() + + +def service_to_entity(apps, _): + Service = apps.get_model("services", "Service") + Entity = apps.get_model("entities", "Entity") + Link = apps.get_model("entities", "Link") + for service in Service.objects.all(): + if service.repository: + log.info("entity.import_services.processing", service=service) + entity = Entity.objects.create( + name=service.name, + owner=service.owner, + description=service.description, + kind=Kind.COMPONENT, + type="service", + source=service.repository, + tags=service.tags, + service=service, + ) + + if service.docs_url: + Link.objects.create( + name="Documentation", url=service.docs_url, entity=entity + ) + + if service.slack_channel: + Link.objects.create( + name="Discussion", + url=f"https://app.slack.com/client/T024Z3H2Y/{service.slack_channel}", + entity=entity, + ) + + +def library_to_entity(apps, _): + Library = apps.get_model("libraries", "Library") + Entity = apps.get_model("entities", "Entity") + Link = apps.get_model("entities", "Link") + for library in Library.objects.all(): + if library.repository: + log.info("entity.import_libraries.processing", library=library) + entity = Entity.objects.create( + name=library.name, + owner=library.owner, + description=library.description, + kind=Kind.COMPONENT, + type="library", + source=library.repository, + tags=library.tags, + library=library, + ) + + if library.docs_url: + Link.objects.create( + name="Documentation", url=library.docs_url, entity=entity + ) + + if library.slack_channel: + Link.objects.create( + name="Discussion", + url=f"https://app.slack.com/client/T024Z3H2Y/{library.slack_channel}", + entity=entity, + ) + + if library.library_url: + Link.objects.create( + name="Library URL", url=library.library_url, entity=entity + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ("entities", "0003_allow_blank_on_group"), + ] + + operations = [ + migrations.RunPython(service_to_entity), + migrations.RunPython(library_to_entity), + ] diff --git a/zoo/entities/models.py b/zoo/entities/models.py index c7c612e5..8013a114 100644 --- a/zoo/entities/models.py +++ b/zoo/entities/models.py @@ -57,7 +57,8 @@ class Meta: group = models.OneToOneField( "entities.Group", on_delete=models.CASCADE, - default=None, + null=True, + blank=True, ) source = models.ForeignKey( "repos.Repository",