-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds documentatoin on code for db fix
- Loading branch information
Showing
5 changed files
with
146 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Fix AAPBRecords `access_level`\n", | ||
"\n", | ||
"This is a quick data fix for a bad default value when creating the `AAPBRecordsBlock` property for `access_level`.\n", | ||
"\n", | ||
"This shouldn't have to be run again, but is provided in case it is useful!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Why?\n", | ||
"When creating The `access_level` value, It was initially set to a tuple, of `(value, label)`, just like the data in the `ChoiceBlock`. However, it needed to be just the `value` only.\n", | ||
"\n", | ||
"Migrating the database back and reapplying the migration left the default values in the database, so this manual fix was needed. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Usage\n", | ||
"Open a python shell in your Wagtail environment:\n", | ||
"\n", | ||
"```sh\n", | ||
"python manage.py shell\n", | ||
"```\n", | ||
"\n", | ||
"Then run the following:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from ov_collections.models import Collection, AAPB_BLOCK_TYPES\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for collection in Collection.objects.all():\n", | ||
" for content in collection.content:\n", | ||
" if content.block_type in AAPB_BLOCK_TYPES:\n", | ||
" if type(content.value['access_level']) is tuple:\n", | ||
" print('fixing', collection.title)\n", | ||
" content.value.update({'access_level': 'online'})\n", | ||
" collection.save()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from exhibits.models import ExhibitPage\n", | ||
"\n", | ||
"for page in ExhibitPage.objects.all():\n", | ||
" for content in page.body:\n", | ||
" if content.block_type in AAPB_BLOCK_TYPES:\n", | ||
" if type(content.value['access_level']) is tuple:\n", | ||
" print('fixing', page.title)\n", | ||
" content.value.update({'access_level': 'online'})\n", | ||
" page.save()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
# Migrate database | ||
|
||
## Show all database migrations | ||
|
||
```bash | ||
ov m showmigrations | ||
``` | ||
|
||
## Generate the migration files | ||
|
||
```bash | ||
ov m makemigrations | ||
``` | ||
|
||
## Run the database migrations | ||
|
||
```bash | ||
ov m migrate | ||
``` |
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