mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-03-29 14:45:29 +00:00
Adds SQL steps to move author data to the new table
This commit is contained in:
parent
4a980cd0e5
commit
ef833f0e42
2 changed files with 47 additions and 4 deletions
44
bookwyrm/migrations/0155_book_new_authors.py
Normal file
44
bookwyrm/migrations/0155_book_new_authors.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
# Generated by Django 3.2.14 on 2022-07-09 21:21
|
||||
|
||||
import bookwyrm.models.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0154_bookauthor"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="book",
|
||||
name="new_authors",
|
||||
field=bookwyrm.models.fields.ManyToManyField(
|
||||
related_name="new_authors",
|
||||
through="bookwyrm.BookAuthor",
|
||||
to="bookwyrm.Author",
|
||||
),
|
||||
),
|
||||
migrations.RunSQL(
|
||||
sql="""
|
||||
INSERT INTO bookwyrm_bookauthor (id, book_id, author_id, created_date, updated_date, author_type)
|
||||
SELECT id, book_id, author_id, NOW(), NOW(), 'author' from bookwyrm_book_authors;
|
||||
""",
|
||||
reverse_sql="""
|
||||
INSERT INTO bookwyrm_book_authors (id, book_id, author_id)
|
||||
SELECT id, book_id, author_id from bookwyrm_bookauthor;
|
||||
""",
|
||||
),
|
||||
migrations.RemoveField(model_name="book", name="authors"),
|
||||
migrations.RenameField(
|
||||
model_name="book", old_name="new_authors", new_name="authors"
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="book",
|
||||
name="authors",
|
||||
field=bookwyrm.models.fields.ManyToManyField(
|
||||
through="bookwyrm.BookAuthor", to="bookwyrm.Author"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -114,10 +114,9 @@ class Book(BookDataModel):
|
|||
subject_places = fields.ArrayField(
|
||||
models.CharField(max_length=255), blank=True, null=True, default=list
|
||||
)
|
||||
authors = fields.ManyToManyField("Author")
|
||||
# authors = fields.ManyToManyField(
|
||||
# "Author", through="BookAuthor", through_fields=("book", "author")
|
||||
# )
|
||||
authors = fields.ManyToManyField(
|
||||
"Author", through="BookAuthor", through_fields=("book", "author")
|
||||
)
|
||||
cover = fields.ImageField(
|
||||
upload_to="covers/", blank=True, null=True, alt_field="alt_text"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue