split maintenance tasks into bare metal / docker

This commit is contained in:
Joel Falknau
2024-09-03 12:24:17 +10:00
parent cbe6c821cc
commit 98efb9f887
12 changed files with 380 additions and 28 deletions

View File

@@ -4,10 +4,25 @@
Your auth project is just a regular Django project - you can add in [other Django apps](https://djangopackages.org/) as desired. Most come with dedicated setup guides, but here is the general procedure:
1. add `'appname',` to your `INSTALLED_APPS` setting in `local.py`
2. run `python manage.py migrate`
3. run `python manage.py collectstatic --noinput`
4. restart AA with `supervisorctl restart myauth:`
::::{tabs}
:::{group-tab} Bare Metal
1. Add `'appname',` to `INSTALLED_APPS` setting in `local.py`
1. Run Migrations `python manage.py migrate`
1. Collect Static Files `python manage.py collectstatic --noinput`
1. Restart our Web Service and Workers `supervisorctl restart myauth:`
:::
:::{group-tab} Containerized
1. Add `'appname',` to `INSTALLED_APPS` setting in `local.py`
1. Restart our Web Service and Workers `docker compose --env-file=.env up -d`
1. Enter a Docker Container `docker compose exec allianceauth_gunicorn bash`
1. Run Migrations `auth migrate`
1. Collect Static Files `auth collectstatic`
:::
::::
## Removing Apps
@@ -25,20 +40,38 @@ First, we want to remove the app related tables from the database.
Let's first try the automatic approach by running the following command:
::::{tabs}
:::{group-tab} Bare Metal
```shell
python manage.py migrate appname zero
```
:::
:::{group-tab} Containerized
```shell
docker compose exec allianceauth_gunicorn bash
python manage.py migrate appname zero
```
:::
::::
If that works, you'll get a confirmation message.
If that did not work, and you got error messages, you will need to remove the tables manually. This is pretty common btw, because many apps use sophisticated table setups, which cannot be removed automatically by Django.
If that did not work, and you got error messages, you will need to remove the tables manually.
> This is pretty common, because many apps use sophisticated table setups, which cannot be removed automatically by Django.
#### Manual table removal
::::{tabs}
:::{group-tab} Bare Metal
First, tell Django that these migrations are no longer in effect (note the additional `--fake`):
```shell
python manage.py migrate appname zero --fake
python manage.py appname zero --fake
```
Then, open the mysql tool and connect to your Alliance Auth database:
@@ -75,6 +108,53 @@ SET FOREIGN_KEY_CHECKS=1;
exit;
```
:::
:::{group-tab} Containerized
First, tell Django that these migrations are no longer in effect (note the additional `--fake`):
```shell
auth migrate appname zero --fake
```
Here we need to swap containers, if you are still inside allianceauth_gunicorn, exit with `exit`
```shell
docker compose exec auth_mysql bash
sudo mysql -u root
use alliance_auth;
```
Next, disable foreign key check. This makes it much easier to drop tables in any order.
```shell
SET FOREIGN_KEY_CHECKS=0;
```
Then get a list of all tables. All tables belonging to the app in question will start with `appname_`.
```shell
show tables;
```
Now, drop the tables from the app one by one like so:
```shell
drop table appname_model_1;
drop table appname_model_2;
...
```
And finally, but very importantly, re-enable foreign key checks again and then exit:
```shell
SET FOREIGN_KEY_CHECKS=1;
exit;
```
:::
::::
### Step 2 - Remove the app from Alliance Auth
Once the tables have been removed, you can remove the app from Alliance Auth. This is done by removing the applabel from the `INSTALLED_APPS` list in your local settings file.