This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(entity): import services and libraries into entity model
- Loading branch information
1 parent
2c8bb9b
commit 84ab43d
Showing
5 changed files
with
112 additions
and
4 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
File renamed without changes.
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,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", | ||
), | ||
), | ||
] |
85 changes: 85 additions & 0 deletions
85
zoo/entities/migrations/0004_import_objects_to_entity_model.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,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), | ||
] |
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