misc: restore migrations and model change (#61944)

This commit is contained in:
Frédéric Péters 2022-02-18 08:29:29 +01:00
parent 700e91af3d
commit 578e4c007e
3 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 2.2.24 on 2022-02-15 10:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('environment', '0021_base_url_validators'),
]
operations = [
migrations.AddField(
model_name='hobo',
name='local',
field=models.BooleanField(default=False),
),
]

View File

@ -0,0 +1,43 @@
# Generated by Django 2.2.24 on 2022-02-15 10:36
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', '0022_local_hobo'),
]
operations = [
migrations.RunPython(populate_local_hobo, clean_local_hobo),
]

View File

@ -459,6 +459,11 @@ class Hobo(ServiceBase):
service_label = _('Deployment Server')
service_default_slug = 'hobo'
# historically an hobo instance did not store information about itself,
# it only stored info about other hobo's.
# now we also store info about an instance on the instance itself, via local=True
local = models.BooleanField(default=False)
def get_admin_zones(self):
return [Zone(self.title, 'hobo', self.get_base_url_path())]