Migrate from BlockVersion.soft to BlockVersion.block_type - follow up
This commit is contained in:
Родитель
03fae8133e
Коммит
d212b9f78d
|
@ -0,0 +1,40 @@
|
|||
# Generated by Django 4.2.16 on 2024-10-31 13:26
|
||||
|
||||
from django.db import migrations
|
||||
import olympia.amo.fields
|
||||
|
||||
def remaining_null_values(apps, schema_editor):
|
||||
BlockVersion = apps.get_model('blocklist', 'BlockVersion')
|
||||
# soft=True -> block_type=1
|
||||
# soft=False -> block_type=0
|
||||
BlockVersion.objects.filter(block_type__isnull=True, soft=True).update(block_type=1)
|
||||
BlockVersion.objects.filter(block_type__isnull=True, soft=False).update(block_type=0)
|
||||
|
||||
|
||||
def convert_block_type_to_soft(apps, schema_editor):
|
||||
BlockVersion = apps.get_model('blocklist', 'BlockVersion')
|
||||
# block_type=1 -> soft=True
|
||||
# block_type=0 -> soft=False
|
||||
BlockVersion.objects.filter(block_type=1).update(soft=True)
|
||||
BlockVersion.objects.filter(block_type=0).update(soft=False)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('blocklist', '0039_auto_20241112_1606'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(remaining_null_values, convert_block_type_to_soft),
|
||||
|
||||
migrations.AlterField(
|
||||
model_name='blockversion',
|
||||
name='block_type',
|
||||
field=olympia.amo.fields.PositiveTinyIntegerField(choices=[(0, 'Blocked'), (1, 'Restricted')], default=0),
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='blockversion',
|
||||
name='soft',
|
||||
),
|
||||
]
|
|
@ -175,7 +175,6 @@ class BlockVersion(ModelBase):
|
|||
block_type = PositiveTinyIntegerField(
|
||||
default=BlockType.BLOCKED,
|
||||
choices=BlockType.choices,
|
||||
null=True,
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
|
|
Загрузка…
Ссылка в новой задаче