-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from BlockVersion.soft to BlockVersion.block_type
This patch does the following: - Introduce `PositiveTinyIntegerField` to support `tinyint unsigned` fields - Rename `soft` to `block_type` via 2 separate migrations (add + remove) - Introduce `BlockType` enum and use it instead of the `soft` boolean - Unify the string versions of enum values
- Loading branch information
Showing
22 changed files
with
229 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/olympia/blocklist/migrations/0037_alter_blockversion_block_type_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 4.2.16 on 2024-10-31 13:26 | ||
|
||
from django.db import migrations | ||
import olympia.amo.fields | ||
|
||
|
||
def convert_soft_to_block_type(apps, schema_editor): | ||
BlockVersion = apps.get_model('blocklist', 'BlockVersion') | ||
# soft=True -> block_type=1 | ||
# soft=False -> block_type=0 | ||
BlockVersion.objects.filter(soft=True).update(block_type=1) | ||
BlockVersion.objects.filter(soft=False).update(block_type=0) | ||
|
||
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('blocklist', '0036_blocklistsubmission_block_type_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='blockversion', | ||
name='block_type', | ||
field=olympia.amo.fields.PositiveTinyIntegerField(choices=[(0, 'Blocked'), (1, 'Restricted')], default=0), | ||
), | ||
migrations.AlterField( | ||
model_name='blocklistsubmission', | ||
name='block_type', | ||
field=olympia.amo.fields.PositiveTinyIntegerField(choices=[(0, 'Blocked'), (1, 'Restricted')], default=0), | ||
), | ||
migrations.RunPython(convert_soft_to_block_type), | ||
] |
27 changes: 27 additions & 0 deletions
27
src/olympia/blocklist/migrations/0038_remove_blockversion_soft.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 4.2.16 on 2024-10-31 13:26 | ||
|
||
from django.db import migrations | ||
import olympia.amo.fields | ||
|
||
|
||
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', '0037_alter_blockversion_block_type_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(migrations.RunPython.noop, convert_block_type_to_soft), | ||
migrations.RemoveField( | ||
model_name='blockversion', | ||
name='soft', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.