misc: remove local hobo instance (#62017)
gitea-wip/hobo/pipeline/head There was a failure building this commit Details
gitea/hobo/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Thomas NOËL 2022-02-21 14:57:11 +01:00
parent 46bad8c2ea
commit 08ce9df1cc
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
from django.db import connection, migrations
from django.urls import reverse
from hobo.environment.utils import get_local_key
def populate_local_hobo(apps, schema_editor):
Hobo = apps.get_model('environment', 'Hobo')
try:
Hobo.objects.get(local=True)
return
except Hobo.DoesNotExist:
pass
if hasattr(connection, 'get_tenant'):
build_absolute_uri = getattr(connection.get_tenant(), 'build_absolute_uri', None)
if build_absolute_uri:
Hobo.objects.create(
secret_key=get_local_key(build_absolute_uri('/')),
title='Hobo',
slug='hobo',
base_url=build_absolute_uri(reverse('home')),
secondary=False,
local=True,
)
def clean_local_hobo(apps, schema_editor):
Hobo = apps.get_model('environment', 'Hobo')
Hobo.objects.filter(local=True).delete()
class Migration(migrations.Migration):
dependencies = [
('environment', '0023_populate_local_hobo'),
]
operations = [
migrations.RunPython(clean_local_hobo, populate_local_hobo),
]