Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Sn
funkwhale
Commits
85dafcb6
Commit
85dafcb6
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Plain Diff
Merge branch 'cover-migration-s3' into 'develop'
Fix
#976
: fix cover attachment migration under S3 Closes
#976
See merge request
!961
parents
73e72113
ad7274ff
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/funkwhale_api/music/migrations/0043_album_cover_attachment.py
+18
-11
18 additions, 11 deletions
...whale_api/music/migrations/0043_album_cover_attachment.py
with
18 additions
and
11 deletions
api/funkwhale_api/music/migrations/0043_album_cover_attachment.py
+
18
−
11
View file @
85dafcb6
...
@@ -13,17 +13,24 @@ def create_attachments(apps, schema_editor):
...
@@ -13,17 +13,24 @@ def create_attachments(apps, schema_editor):
if
path
.
lower
().
endswith
(
'
.png
'
):
if
path
.
lower
().
endswith
(
'
.png
'
):
return
"
image/png
"
return
"
image/png
"
return
"
image/jpeg
"
return
"
image/jpeg
"
qs
=
Album
.
objects
.
filter
(
attachment_cover
=
None
).
exclude
(
cover
=
""
).
exclude
(
cover
=
None
)
for
album
in
Album
.
objects
.
filter
(
attachment_cover
=
None
).
exclude
(
cover
=
""
).
exclude
(
cover
=
None
):
total
=
qs
.
count
()
try
:
print
(
'
Creating attachments for {} album covers, this may take a while…
'
.
format
(
total
))
album_attachment_mapping
[
album
]
=
Attachment
(
from
django.core.files.storage
import
FileSystemStorage
file
=
album
.
cover
,
for
i
,
album
in
enumerate
(
qs
):
size
=
album
.
cover
.
size
,
if
isinstance
(
album
.
cover
.
storage
.
_wrapped
,
FileSystemStorage
):
mimetype
=
get_mimetype
(
album
.
cover
.
path
),
try
:
)
size
=
album
.
cover
.
size
except
FileNotFoundError
:
except
FileNotFoundError
:
print
(
'
Skipping missing cover file {}
'
.
format
(
album
.
cover
.
path
))
# can occur when file isn't found on disk or S3
print
(
"
Warning: cover file wasn
'
t found in storage: {}
"
.
format
(
e
.
__class__
))
size
=
None
album_attachment_mapping
[
album
]
=
Attachment
(
file
=
album
.
cover
,
size
=
None
,
mimetype
=
get_mimetype
(
album
.
cover
.
name
),
)
print
(
'
Commiting changes…
'
)
Attachment
.
objects
.
bulk_create
(
album_attachment_mapping
.
values
(),
batch_size
=
2000
)
Attachment
.
objects
.
bulk_create
(
album_attachment_mapping
.
values
(),
batch_size
=
2000
)
# map each attachment to the corresponding album
# map each attachment to the corresponding album
# and bulk save
# and bulk save
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment