GSoC 2022: Toolkit for StreamField data migrations in Wagtail #8156
Replies: 7 comments 4 replies
-
Related issue: #2110 (Migrating a Block within a StreamField) At CFPB we have also developed some code for StreamField data migrations that lives here and is documented here. Our approach (which could certainly be improved upon!) tries to address migration of both the page itself as well as any historic revisions that also contain serialized versions of the StreamField data. |
Beta Was this translation helpful? Give feedback.
-
Notes from today’s meeting, based on questions from Sandil:
|
Beta Was this translation helpful? Give feedback.
-
Hello, I am interested in this idea and can you recommend to me some pre-works about this? |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot!I'll have a try !
…---- 回复的原邮件 ----
| 发件人 | Jacob ***@***.***> |
| 日期 | 2022年04月01日 16:40 |
| 收件人 | ***@***.***> |
| 抄送至 | ***@***.******@***.***> |
| 主题 | Re: [wagtail/wagtail] GSoC 2022: Toolkit for StreamField data migrations in Wagtail (Discussion #8156) |
Hi @xgdyp, welcome and thanks for your interest! I don't know exactly what you mean by preworks. If you want background, I think reading through the links @chosak has added would be a good start. If you'd like to experiment yourself, start by setting up a development environment (https://docs.wagtail.org/en/stable/contributing/developing.html). If you're not familiar with Django's data migrations already, making a change to a non-Streamfield and writing a data migration (for example, making a ForeignKey non-nullable, so it needs a migration to add a default) using https://docs.djangoproject.com/en/4.0/topics/migrations/#data-migrations-1 would be beneficial. I'd then progress to making changes to StreamField and generating migrations. What do they look like? Which kind of changes cause you to lose data or break things currently? I'd then have a go at hand writing a StreamField data migration that addresses a basic change, such as renaming a block, so you don't lose data - this will give you a sense of what this project aims to make easier. Feel free to ask any questions you encounter!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I'm taking this project, and gonna collaboratively work on this 👍 |
Beta Was this translation helpful? Give feedback.
-
Progress so Far: For now, we have decided to develop this as a separate package. https://github.com/sandilsranasinghe/wagtail-streamfield-migration-toolkit So far we've developed an approach which could be split into 3 parts:
For the recursion process we are working with raw JSON like data. We use the current block definitions to identify different types of structures (StreamBlocks, StructBlocks, ListBlocks) when recursing (for now we have not taken block definitions which differ from the actual data into consideration).
Operations are classes which have an apply method which will be called for all end blocks matching the given block path from the recursion process. This will contain the logic for altering the block value. We will be having a few operations available for from the package for basic/common use cases. We have the following for now.
Users will be able to define custom operations for any use cases they want, and we will try to include operations requested by the community as we go on. For example, the simplest operation which changes a block value would look like,
When querying data one important consideration is avoiding validation which can remove data which is not in the structure of our current block definitions. For this we're using an annotation when querying to get the raw json data straight from the database column completely avoiding validation. Afterwards a list of operations can be applied on the data with the above recursion process for each page. Note that any non page models with streamfields can also be updated. What we are looking to work on next include a management command to easily generate code for migration files, an autodetect feature to detect limited changes (rename and remove) |
Beta Was this translation helpful? Give feedback.
-
Initial version of package 0.1.0 published at https://pypi.org/project/wagtail-streamfield-migration-toolkit/ This is still in the early stages of development, so any feedback would be most appreciated. Note that work is still underway on improving the autodetect feature. |
Beta Was this translation helpful? Give feedback.
-
Discussion about Toolkit for StreamField data migrations in Wagtail a Google Summer of Code project.
Beta Was this translation helpful? Give feedback.
All reactions