mirror of
https://github.com/ansible/awx.git
synced 2026-02-12 07:04:45 -03:30
* allow pytest --migrations to succeed * We actually subvert migrations from running in test via pytest.ini --no-migrations option. This has led to bit rot for the sqlite migrations happy path. This changeset pays off that tech debt and allows for an sqlite migration happy path. * This paves the way for programatic invocation of individual migrations and weaving of the creation of resources (i.e. Instance, Job Template, etc). With this, a developer can instantiate various database states, trigger a migration, assert the state of the db, and then have pytest rollback all of that. * I will note that in practice, running these migrations is dog shit slow BUT this work also opens up the possibility of saving and re-using sqlite3 database files. Normally, caching is not THE answer and causes more harm than good. But in this case, our migrations are mostly write-once (I say mostly because this change set violates that :) so cache invalidation isn't a major issue. * functional test for migrations on sqlite * We commonly subvert running migrations in test land. Test land uses sqlite. By not constantly exercising this code path it atrophies. The smoke test here is to continuously exercise that code path. * Add ci test to run migration tests separately, they take =~ 2-3 minutes each on my laptop. * The smoke tests also serves as an example of how to write migration tests. * run migration tests in ci
290 lines
11 KiB
Python
290 lines
11 KiB
Python
# Generated by Django 4.2.3 on 2023-08-02 13:18
|
|
|
|
import awx.main.models.notifications
|
|
from django.db import migrations, models
|
|
|
|
from ._sqlite_helper import dbawaremigrations
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
('main', '0184_django_indexes'),
|
|
('conf', '0010_change_to_JSONField'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AlterField(
|
|
model_name='instancegroup',
|
|
name='policy_instance_list',
|
|
field=models.JSONField(
|
|
blank=True, default=list, help_text='List of exact-match Instances that will always be automatically assigned to this group'
|
|
),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='jobtemplate',
|
|
name='survey_spec',
|
|
field=models.JSONField(blank=True, default=dict),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='notificationtemplate',
|
|
name='messages',
|
|
field=models.JSONField(
|
|
blank=True,
|
|
default=awx.main.models.notifications.NotificationTemplate.default_messages,
|
|
help_text='Optional custom messages for notification template.',
|
|
null=True,
|
|
),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='notificationtemplate',
|
|
name='notification_configuration',
|
|
field=models.JSONField(default=dict),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='project',
|
|
name='inventory_files',
|
|
field=models.JSONField(
|
|
blank=True,
|
|
default=list,
|
|
editable=False,
|
|
help_text='Suggested list of content that could be Ansible inventory in the project',
|
|
verbose_name='Inventory Files',
|
|
),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='project',
|
|
name='playbook_files',
|
|
field=models.JSONField(blank=True, default=list, editable=False, help_text='List of playbooks found in the project', verbose_name='Playbook Files'),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='schedule',
|
|
name='char_prompts',
|
|
field=models.JSONField(blank=True, default=dict),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='schedule',
|
|
name='survey_passwords',
|
|
field=models.JSONField(blank=True, default=dict, editable=False),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='workflowjobtemplate',
|
|
name='char_prompts',
|
|
field=models.JSONField(blank=True, default=dict),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='workflowjobtemplate',
|
|
name='survey_spec',
|
|
field=models.JSONField(blank=True, default=dict),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='workflowjobtemplatenode',
|
|
name='char_prompts',
|
|
field=models.JSONField(blank=True, default=dict),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='workflowjobtemplatenode',
|
|
name='survey_passwords',
|
|
field=models.JSONField(blank=True, default=dict, editable=False),
|
|
),
|
|
# These are potentially a problem. Move the existing fields
|
|
# aside while pretending like they've been deleted, then add
|
|
# in fresh empty fields. Make the old fields nullable where
|
|
# needed while we are at it, so that new rows don't hit
|
|
# IntegrityError. We'll do the data migration out-of-band
|
|
# using a task.
|
|
migrations.RunSQL( # Already nullable
|
|
"ALTER TABLE main_activitystream RENAME deleted_actor TO deleted_actor_old;",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='activitystream',
|
|
name='deleted_actor',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='activitystream',
|
|
name='deleted_actor',
|
|
field=models.JSONField(null=True),
|
|
),
|
|
dbawaremigrations.RunSQL(
|
|
"""
|
|
ALTER TABLE main_activitystream RENAME setting TO setting_old;
|
|
ALTER TABLE main_activitystream ALTER COLUMN setting_old DROP NOT NULL;
|
|
""",
|
|
sqlite_sql="ALTER TABLE main_activitystream RENAME setting TO setting_old",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='activitystream',
|
|
name='setting',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='activitystream',
|
|
name='setting',
|
|
field=models.JSONField(blank=True, default=dict),
|
|
),
|
|
dbawaremigrations.RunSQL(
|
|
"""
|
|
ALTER TABLE main_job RENAME survey_passwords TO survey_passwords_old;
|
|
ALTER TABLE main_job ALTER COLUMN survey_passwords_old DROP NOT NULL;
|
|
""",
|
|
sqlite_sql="ALTER TABLE main_job RENAME survey_passwords TO survey_passwords_old",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='job',
|
|
name='survey_passwords',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='job',
|
|
name='survey_passwords',
|
|
field=models.JSONField(blank=True, default=dict, editable=False),
|
|
),
|
|
dbawaremigrations.RunSQL(
|
|
"""
|
|
ALTER TABLE main_joblaunchconfig RENAME char_prompts TO char_prompts_old;
|
|
ALTER TABLE main_joblaunchconfig ALTER COLUMN char_prompts_old DROP NOT NULL;
|
|
""",
|
|
sqlite_sql="ALTER TABLE main_joblaunchconfig RENAME char_prompts TO char_prompts_old",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='joblaunchconfig',
|
|
name='char_prompts',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='joblaunchconfig',
|
|
name='char_prompts',
|
|
field=models.JSONField(blank=True, default=dict),
|
|
),
|
|
dbawaremigrations.RunSQL(
|
|
"""
|
|
ALTER TABLE main_joblaunchconfig RENAME survey_passwords TO survey_passwords_old;
|
|
ALTER TABLE main_joblaunchconfig ALTER COLUMN survey_passwords_old DROP NOT NULL;
|
|
""",
|
|
sqlite_sql="ALTER TABLE main_joblaunchconfig RENAME survey_passwords TO survey_passwords_old;",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='joblaunchconfig',
|
|
name='survey_passwords',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='joblaunchconfig',
|
|
name='survey_passwords',
|
|
field=models.JSONField(blank=True, default=dict, editable=False),
|
|
),
|
|
dbawaremigrations.RunSQL(
|
|
"""
|
|
ALTER TABLE main_notification RENAME body TO body_old;
|
|
ALTER TABLE main_notification ALTER COLUMN body_old DROP NOT NULL;
|
|
""",
|
|
sqlite_sql="ALTER TABLE main_notification RENAME body TO body_old",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='notification',
|
|
name='body',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='notification',
|
|
name='body',
|
|
field=models.JSONField(blank=True, default=dict),
|
|
),
|
|
dbawaremigrations.RunSQL(
|
|
"""
|
|
ALTER TABLE main_unifiedjob RENAME job_env TO job_env_old;
|
|
ALTER TABLE main_unifiedjob ALTER COLUMN job_env_old DROP NOT NULL;
|
|
""",
|
|
sqlite_sql="ALTER TABLE main_unifiedjob RENAME job_env TO job_env_old",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='unifiedjob',
|
|
name='job_env',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='unifiedjob',
|
|
name='job_env',
|
|
field=models.JSONField(blank=True, default=dict, editable=False),
|
|
),
|
|
dbawaremigrations.RunSQL(
|
|
"""
|
|
ALTER TABLE main_workflowjob RENAME char_prompts TO char_prompts_old;
|
|
ALTER TABLE main_workflowjob ALTER COLUMN char_prompts_old DROP NOT NULL;
|
|
""",
|
|
sqlite_sql="ALTER TABLE main_workflowjob RENAME char_prompts TO char_prompts_old",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='workflowjob',
|
|
name='char_prompts',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='workflowjob',
|
|
name='char_prompts',
|
|
field=models.JSONField(blank=True, default=dict),
|
|
),
|
|
dbawaremigrations.RunSQL(
|
|
"""
|
|
ALTER TABLE main_workflowjob RENAME survey_passwords TO survey_passwords_old;
|
|
ALTER TABLE main_workflowjob ALTER COLUMN survey_passwords_old DROP NOT NULL;
|
|
""",
|
|
sqlite_sql="ALTER TABLE main_workflowjob RENAME survey_passwords TO survey_passwords_old",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='workflowjob',
|
|
name='survey_passwords',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='workflowjob',
|
|
name='survey_passwords',
|
|
field=models.JSONField(blank=True, default=dict, editable=False),
|
|
),
|
|
dbawaremigrations.RunSQL(
|
|
"""
|
|
ALTER TABLE main_workflowjobnode RENAME char_prompts TO char_prompts_old;
|
|
ALTER TABLE main_workflowjobnode ALTER COLUMN char_prompts_old DROP NOT NULL;
|
|
""",
|
|
sqlite_sql="ALTER TABLE main_workflowjobnode RENAME char_prompts TO char_prompts_old",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='workflowjobnode',
|
|
name='char_prompts',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='workflowjobnode',
|
|
name='char_prompts',
|
|
field=models.JSONField(blank=True, default=dict),
|
|
),
|
|
dbawaremigrations.RunSQL(
|
|
"""
|
|
ALTER TABLE main_workflowjobnode RENAME survey_passwords TO survey_passwords_old;
|
|
ALTER TABLE main_workflowjobnode ALTER COLUMN survey_passwords_old DROP NOT NULL;
|
|
""",
|
|
sqlite_sql="ALTER TABLE main_workflowjobnode RENAME survey_passwords TO survey_passwords_old",
|
|
state_operations=[
|
|
migrations.RemoveField(
|
|
model_name='workflowjobnode',
|
|
name='survey_passwords',
|
|
),
|
|
],
|
|
),
|
|
migrations.AddField(
|
|
model_name='workflowjobnode',
|
|
name='survey_passwords',
|
|
field=models.JSONField(blank=True, default=dict, editable=False),
|
|
),
|
|
]
|