-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy old quality profile values into new, rename old vs new quality p…
…rofile model field names
- Loading branch information
Showing
11 changed files
with
226 additions
and
81 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 was deleted.
Oops, something went wrong.
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,54 @@ | ||
# Generated by Django 3.0.2 on 2024-07-28 13:12 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('nefarious', '0078_nefarioussettings_jackett_filter_index'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='QualityProfile', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=500, unique=True)), | ||
('quality', models.CharField(choices=[('any', 'any'), ('sd', 'sd'), ('hd-720p', 'hd-720p'), ('hd-720p-1080p', 'hd-720p-1080p'), ('hd-1080p', 'hd-1080p'), ('ultra-hd', 'ultra-hd')], max_length=500)), | ||
('min_size_gb', models.DecimalField(blank=True, decimal_places=2, help_text='minimum size (gb) to download', max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])), | ||
('max_size_gb', models.DecimalField(blank=True, decimal_places=2, help_text='maximum size (gb) to download', max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])), | ||
], | ||
), | ||
migrations.AlterModelOptions( | ||
name='nefarioussettings', | ||
options={'verbose_name_plural': 'Settings'}, | ||
), | ||
migrations.AddField( | ||
model_name='nefarioussettings', | ||
name='quality_profile_movies_default', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='quality_profile_movies_default', to='nefarious.QualityProfile'), | ||
), | ||
migrations.AddField( | ||
model_name='nefarioussettings', | ||
name='quality_profile_tv_default', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='quality_profile_tv_default', to='nefarious.QualityProfile'), | ||
), | ||
migrations.AddField( | ||
model_name='watchmovie', | ||
name='quality_profile', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='nefarious.QualityProfile'), | ||
), | ||
migrations.AddField( | ||
model_name='watchtvseasonrequest', | ||
name='quality_profile', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='nefarious.QualityProfile'), | ||
), | ||
migrations.AddField( | ||
model_name='watchtvshow', | ||
name='quality_profile', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='nefarious.QualityProfile'), | ||
), | ||
] |
36 changes: 36 additions & 0 deletions
36
src/nefarious/migrations/0080_populate_quality_profiles.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,36 @@ | ||
from django.db import migrations, transaction | ||
from nefarious.quality import PROFILES | ||
|
||
|
||
def populate_quality_profile(apps, schema_editor): | ||
NefariousSettings = apps.get_model('nefarious', 'NefariousSettings') | ||
QualityProfile = apps.get_model('nefarious', 'QualityProfile') | ||
|
||
nefarious_settings = NefariousSettings.objects.get() | ||
|
||
# copy values from old field | ||
for profile in PROFILES: | ||
QualityProfile.objects.create( | ||
name=profile, | ||
quality=profile, | ||
) | ||
|
||
quality_profile_tv = QualityProfile.objects.filter(quality=nefarious_settings.quality_profile_tv).first() | ||
quality_profile_movies = QualityProfile.objects.filter(quality=nefarious_settings.quality_profile_movies).first() | ||
|
||
nefarious_settings.quality_profile_tv_default = quality_profile_tv | ||
nefarious_settings.quality_profile_movies_default = quality_profile_movies | ||
|
||
with transaction.atomic(): | ||
nefarious_settings.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('nefarious', '0079_auto_20240728_1312'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(populate_quality_profile, reverse_code=lambda a, b: None), | ||
] |
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
src/nefarious/migrations/0081_populate_quality_profile_media.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 3.0.2 on 2024-07-27 21:07 | ||
|
||
from django.db import migrations, transaction | ||
|
||
|
||
def populate_quality_profile_media(apps, schema_editor): | ||
QualityProfile = apps.get_model('nefarious', 'QualityProfile') | ||
WatchMovie = apps.get_model('nefarious', 'WatchMovie') | ||
WatchTVShow = apps.get_model('nefarious', 'WatchTVShow') | ||
WatchTVSeasonRequest = apps.get_model('nefarious', 'WatchTVSeasonRequest') | ||
|
||
# copy default quality profile into new field | ||
for model in [WatchMovie, WatchTVShow, WatchTVSeasonRequest]: | ||
for media in model.objects.all(): | ||
if media.quality_profile_custom: | ||
# find matching quality profile by the quality & type | ||
quality_profile = QualityProfile.objects.filter( | ||
quality=media.quality_profile_custom, | ||
).first() | ||
# assign quality profile | ||
media.quality_profile = quality_profile | ||
# must save in transaction | ||
with transaction.atomic(): | ||
media.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('nefarious', '0080_populate_quality_profiles'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(populate_quality_profile_media, reverse_code=lambda a, b: None), | ||
] |
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,21 @@ | ||
# Generated by Django 3.0.2 on 2024-07-28 14:17 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('nefarious', '0081_populate_quality_profile_media'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='nefarioussettings', | ||
name='quality_profile_movies', | ||
), | ||
migrations.RemoveField( | ||
model_name='nefarioussettings', | ||
name='quality_profile_tv', | ||
), | ||
] |
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,23 @@ | ||
# Generated by Django 3.0.2 on 2024-07-28 14:18 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('nefarious', '0082_auto_20240728_1417'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='nefarioussettings', | ||
old_name='quality_profile_movies_default', | ||
new_name='quality_profile_movies', | ||
), | ||
migrations.RenameField( | ||
model_name='nefarioussettings', | ||
old_name='quality_profile_tv_default', | ||
new_name='quality_profile_tv', | ||
), | ||
] |
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,25 @@ | ||
# Generated by Django 3.0.2 on 2024-07-28 17:52 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('nefarious', '0083_auto_20240728_1418'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='watchmovie', | ||
name='quality_profile_custom', | ||
), | ||
migrations.RemoveField( | ||
model_name='watchtvseasonrequest', | ||
name='quality_profile_custom', | ||
), | ||
migrations.RemoveField( | ||
model_name='watchtvshow', | ||
name='quality_profile_custom', | ||
), | ||
] |
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