Files
Cedar-Django/closedverse_main/migrations/0004_auto_20231016_1419.py
T
some weird guy e5c99e0248 File sharing update (requires migrations for existing databases)
There are a bunch of migration files that have been thrown into the repository. Sadly, migrating is a huge pain in the fucking ass, you may need to rollback your database or god knows what.

- did not add change logs too lazy
2023-10-16 15:22:41 -07:00

61 lines
1.6 KiB
Python

# Generated by Django 3.2.2 on 2023-10-16 21:19
from django.db import migrations
def migrate_media_to_file(apps, schema_editor):
# Migrate Comment model
Comment = apps.get_model('closedverse_main', 'Comment')
for comment in Comment.objects.all():
if comment.drawing and comment.drawing.startswith('/i/'):
comment.file = comment.drawing[3:]
comment.save()
if comment.screenshot and comment.screenshot.startswith('/i/'):
comment.file = comment.screenshot[3:]
comment.save()
# Migrate Message model
Message = apps.get_model('closedverse_main', 'Message')
for message in Message.objects.all():
if message.drawing and message.drawing.startswith('/i/'):
message.file = message.drawing[3:]
message.save()
if message.screenshot and message.screenshot.startswith('/i/'):
message.file = message.screenshot[3:]
message.save()
# Migrate Post model
Post = apps.get_model('closedverse_main', 'Post')
for post in Post.objects.all():
if post.drawing and post.drawing.startswith('/i/'):
post.file = post.drawing[3:]
post.save()
if post.screenshot and post.screenshot.startswith('/i/'):
post.file = post.screenshot[3:]
post.save()
if post.video and post.video.startswith('/i/'):
post.file = post.video[3:]
post.save()
User = apps.get_model('closedverse_main', 'User')
for user in User.objects.all():
user.avatar_input = user.avatar
if user.has_mh:
user.avatar_type = 2
else:
user.avatar_type = 1
user.save()
class Migration(migrations.Migration):
dependencies = [
('closedverse_main', '0003_auto_20231016_1410'),
]
operations = [
migrations.RunPython(migrate_media_to_file),
]