Skip to content

Commit

Permalink
Adds documentatoin on code for db fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mrharpo committed Dec 16, 2024
1 parent 894fae1 commit 4248b4a
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 39 deletions.
106 changes: 106 additions & 0 deletions docs/dev/fix_AAPBRecords.ipynb
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
}
25 changes: 7 additions & 18 deletions docs/dev.md → docs/dev/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,6 @@ COMMANDS:

: Enter into a python django shell interpreter, with the application context loaded.

## Examples

The following are some useful examples of development commands that might be run:

### Migrate database

Generating the migration files can be accomplished with:

```bash
ov m makemigrations
```

To Run the database migrations:

```bash
ov m migrate
```

### Show the logs

Show the docker compose logs
Expand All @@ -92,3 +74,10 @@ Show logs for just the frontend
```bash
ov c logs ov-frontend
```

## Examples

The following are some useful examples of development commands that might be run:

- [Database migrations](./migrate)
- [Fix database records](./fix_AAPBRecords)
20 changes: 20 additions & 0 deletions docs/dev/migrate.md
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
```
5 changes: 4 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ edit_uri: ''
nav:
- Home: index.md
- Setup: setup.md
- Develop: dev.md
- Develop:
- dev/index.md
- dev/migrate.md
- dev/fix_AAPBRecords.ipynb
- Maintenance: maintenance.md
- Reference: reference
markdown_extensions:
Expand Down
29 changes: 9 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,14 @@ dependencies = [
requires-python = '~=3.10'

[dependency-groups]
dev = [
"black~=24.10.0",
"ruff~=0.8.2",
"pre-commit~=4.0.1",
]
dev = ["black~=24.10.0", "ruff~=0.8.2", "pre-commit~=4.0.1"]
docs = [
"mkdocs~=1.6.1",
"mkdocs-material~=9.5.48",
"mike~=2.1.3",
"mkdocstrings[python]~=0.27.0",
"mkdocs-git-revision-date-localized-plugin~=1.3.0",
"mkdocs-jupyter~=0.25.1",
"mkdocs~=1.6.1",
"mkdocs-material~=9.5.48",
"mike~=2.1.3",
"mkdocstrings[python]~=0.27.0",
"mkdocs-git-revision-date-localized-plugin~=1.3.0",
"mkdocs-jupyter~=0.25.1",
]
test = [
"pytest~=8.3.4",
Expand All @@ -52,15 +42,8 @@ test = [
]

[project.optional-dependencies]
cli = [
"typer~=0.15.1",
"loguru~=0.7.3",
"trogon~=0.6.0",
]
production = [
"gunicorn[standard]~=23.0.0",
"django-storages[s3]~=1.14.4",
]
cli = ["typer~=0.15.1", "loguru~=0.7.3", "trogon~=0.6.0"]
production = ["gunicorn[standard]~=23.0.0", "django-storages[s3]~=1.14.4"]

[project.urls]
documentation = 'https://wgbh-mla.github.io/ov-wag/'
Expand All @@ -87,21 +70,27 @@ version = { source = 'file', path = 'ov_wag/_version.py' }
[tool.pdm.scripts]
# Development
dev = { shell = 'python manage.py runserver' }

# Migrations
makemigrations = { shell = 'python manage.py makemigrations' }
migrate = { shell = 'python manage.py migrate' }

# Dependency management
## Lockfiles
lock-dev = { shell = 'pdm lock -G dev,test,cli' }
lock-prod = { shell = 'pdm lock -G production -L pdm-locks/pdm.prod.lock' }
lock-docs = { shell = 'pdm lock -G docs -L pdm-locks/pdm.doc.lock' }
locks = { composite = ['lock-dev', 'lock-prod', 'lock-docs'] }

## Upgrades
upgrade = { shell = 'pdm update -G dev,test,cli -u --no-sync --no-self' }
upgrade-prod = { shell = 'pdm update --no-default -G production -L pdm-locks/pdm.prod.lock -u --no-sync --no-self' }
upgrade-docs = { shell = 'pdm update --no-default -G docs -L pdm-locks/pdm.doc.lock -u --no-sync --no-self' }
upgrade-all = { composite = ['upgrade', 'upgrade-prod', 'upgrade-docs'] }

# Docs
docs = { shell = 'mkdocs serve' }

[lint]
select = [
'B', # flake8-bugbear
Expand Down

0 comments on commit 4248b4a

Please sign in to comment.