mirror of
https://github.com/ansible/awx.git
synced 2026-03-27 05:45:02 -02:30
Moved the AddField operation before the RunPython operations for 'rename_jts' and 'rename_projects' in migration 0200_template_name_constraint.py. This ensures the new 'org_unique' field exists before related data migrations are executed. Fix ``` django.db.utils.ProgrammingError: column main_unifiedjobtemplate.org_unique does not exist ``` while applying migration 0200_template_name_constraint.py when there's a job template or poject with duplicate name in the same org
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
# Generated by Django 4.2.20 on 2025-04-22 15:54
|
|
|
|
import logging
|
|
|
|
from django.db import migrations, models
|
|
|
|
from awx.main.migrations._db_constraints import _rename_duplicates
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def rename_jts(apps, schema_editor):
|
|
cls = apps.get_model('main', 'JobTemplate')
|
|
_rename_duplicates(cls)
|
|
|
|
|
|
def rename_projects(apps, schema_editor):
|
|
cls = apps.get_model('main', 'Project')
|
|
_rename_duplicates(cls)
|
|
|
|
|
|
def change_inventory_source_org_unique(apps, schema_editor):
|
|
cls = apps.get_model('main', 'InventorySource')
|
|
r = cls.objects.update(org_unique=False)
|
|
logger.info(f'Set database constraint rule for {r} inventory source objects')
|
|
|
|
|
|
def rename_wfjt(apps, schema_editor):
|
|
cls = apps.get_model('main', 'WorkflowJobTemplate')
|
|
_rename_duplicates(cls)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('main', '0199_inventorygroupvariableswithhistory_and_more'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name='unifiedjobtemplate',
|
|
name='org_unique',
|
|
field=models.BooleanField(blank=True, default=True, editable=False, help_text='Used internally to selectively enforce database constraint on name'),
|
|
),
|
|
migrations.RunPython(rename_jts, migrations.RunPython.noop),
|
|
migrations.RunPython(rename_projects, migrations.RunPython.noop),
|
|
migrations.RunPython(rename_wfjt, migrations.RunPython.noop),
|
|
migrations.RunPython(change_inventory_source_org_unique, migrations.RunPython.noop),
|
|
migrations.AddConstraint(
|
|
model_name='unifiedjobtemplate',
|
|
constraint=models.UniqueConstraint(
|
|
condition=models.Q(('org_unique', True)), fields=('polymorphic_ctype', 'name', 'organization'), name='ujt_hard_name_constraint'
|
|
),
|
|
),
|
|
]
|