2021-12-24 13:53:55 -08:00
NiceDB / NeoDB - Getting Start
==============================
This is a very basic guide with limited detail, contributions welcomed
2023-07-24 13:39:49 +02:00
## Table of Contents
2023-08-17 02:09:36 -04:00
- [Run in Docker ](#0-run-in-docker )
- [1 Install ](#1-manual-install )
2023-07-24 13:39:49 +02:00
* [1.1 Database ](#11-database )
* [1.2 Configuration ](#12-configuration )
2023-07-24 13:47:13 +02:00
* [1.3 Packages and Build ](#13-packages-and-build )
2023-07-24 13:39:49 +02:00
- [2 Start services ](#2-start-services )
- [3 Migrate from an earlier version ](#3-migrate-from-an-earlier-version )
2023-07-24 13:47:13 +02:00
- [4 Add Cron Jobs (optional) ](#4-add-cron-jobs-optional )
- [5 Index and Search (optional) ](#5-index-and-search-optional )
- [6 Other maintenance tasks (optional) ](#6-other-maintenance-tasks-optional )
2023-07-24 13:39:49 +02:00
- [7 Frequently Asked Questions ](#7-frequently-asked-questions )
2023-08-17 02:09:36 -04:00
0 Run in Docker
---------------
```
cp neodb.env.dist neodb.env # update this configuration
docker-compose up
```
1 Manual Install
----------------
2023-01-05 03:06:13 -05:00
Install PostgreSQL, Redis and Python (3.10 or above) if not yet
2021-12-24 13:53:55 -08:00
2023-07-24 13:39:49 +02:00
### 1.1 Database
2021-12-24 13:53:55 -08:00
Setup database
```
CREATE ROLE neodb with LOGIN ENCRYPTED PASSWORD 'abadface';
2023-07-20 21:59:49 -04:00
CREATE DATABASE neodb ENCODING 'UTF8' LC_COLLATE='en_US.UTF-8' LC_CTYPE='en_US.UTF-8' TEMPLATE template0;
2021-12-24 13:53:55 -08:00
GRANT ALL ON DATABASE neodb TO neodb;
```
2023-07-24 13:39:49 +02:00
### 1.2 Configuration
2021-12-24 13:53:55 -08:00
Create and edit your own configuration file (optional but very much recommended)
```
mkdir mysite & & cp boofilsic/settings.py mysite/
export DJANGO_SETTINGS_MODULE=mysite.settings
```
2023-01-11 22:52:07 -05:00
Alternatively you can have a configuration file import `boofilsic/settings.py` then override it:
```
from boofilsic.settings import *
SECRET_KEY = "my_key"
```
2023-07-24 13:39:49 +02:00
The most important configurations to setup are:
2023-08-10 16:01:40 -04:00
- `MASTODON_ALLOW_ANY_SITE` set to `True` so that user can login via any Mastodon API compatible sites (e.g. Mastodon/Pleroma)
2023-07-24 13:39:49 +02:00
- `REDIRECT_URIS` should be `SITE_INFO["site_url"] + "/account/login/oauth"` . If you want to run **on local** , `SITE_INFO["site_url"]` should be set to `"http://localhost/"`
2022-12-13 16:33:58 -05:00
More details on `settings.py` in [configuration.md ](configuration.md )
2021-12-24 13:53:55 -08:00
2023-07-24 13:47:13 +02:00
### 1.3 Packages and Build
2023-01-11 22:52:07 -05:00
Create and use `venv` as you normally would, then install packages
2021-12-24 13:53:55 -08:00
```
python3 -m pip install -r requirements.txt
2023-01-11 22:52:07 -05:00
2021-12-24 13:53:55 -08:00
```
Quick check
```
python3 manage.py check
```
Initialize database
```
python3 manage.py migrate
```
2023-06-01 14:49:19 -04:00
Build static assets (production only)
2021-12-24 13:53:55 -08:00
```
2023-05-20 11:01:18 -04:00
python3 manage.py compilescss
2021-12-24 13:53:55 -08:00
python3 manage.py collectstatic
```
2023-07-24 13:39:49 +02:00
2 Start services
2021-12-24 13:53:55 -08:00
--------------
Make sure PostgreSQL and Redis are running
Start job queue server
```
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES # required and only for macOS, otherwise it may crash
2023-01-11 22:52:07 -05:00
python3 manage.py rqworker --with-scheduler import export mastodon fetch crawl
2021-12-24 13:53:55 -08:00
```
Run web server in dev mode
```
2023-01-11 22:52:07 -05:00
python3 manage.py runserver
2021-12-24 13:53:55 -08:00
```
It should be ready to serve from here, to run web server for production, consider `gunicorn -w 8 boofilsic.wsgi` in systemd or sth similar
2023-08-10 16:01:40 -04:00
3 Migrate from an earlier version
2021-12-24 13:53:55 -08:00
-------------------------------
Update database
```
python3 manage.py migrate
```
Rebuild static assets
```
2023-06-09 03:05:42 -04:00
python3 manage.py compilescss
2021-12-24 13:53:55 -08:00
python3 manage.py collectstatic
```
2023-07-24 13:39:49 +02:00
4 Add Cron Jobs (optional)
2022-07-31 03:07:11 -04:00
-------------
add `python manage.py refresh_mastodon` to crontab to run hourly, it will refresh cached users' follow/mute/block from mastodon
2023-07-24 13:39:49 +02:00
5 Index and Search (optional)
2022-07-31 02:37:59 -04:00
----------------
Install TypeSense or Meilisearch, change `SEARCH_BACKEND` and coniguration for search server in `settings.py`
Build initial index, it may take a few minutes or hours
```
2023-01-11 22:52:07 -05:00
python3 manage.py index --init
python3 manage.py index --reindex
2022-07-31 02:37:59 -04:00
```
2021-12-24 13:53:55 -08:00
2023-07-24 13:39:49 +02:00
6 Other maintenance tasks (optional)
2021-12-24 13:53:55 -08:00
-----------------------
2023-01-11 22:52:07 -05:00
Requeue failed import jobs
2021-12-24 13:53:55 -08:00
```
2023-01-11 22:52:07 -05:00
rq requeue --all --queue import
2021-12-24 13:53:55 -08:00
```
2022-09-13 15:47:35 -04:00
2022-11-10 14:17:48 -05:00
Run Tests
```
coverage run --source='.' manage.py test
coverage report
```
2023-06-02 21:54:48 -04:00
Enable Developer Console
```
python3 manage.py createapplication --client-id NEODB_DEVELOPER_CONSOLE --skip-authorization --name 'NeoDB Developer Console' --redirect-uris 'https://example.org/lol' confidential authorization-code
```
2023-07-24 13:39:49 +02:00
7 Frequently Asked Questions
------
### I got Error: “无效的登录回调地址”.
2023-08-10 16:01:40 -04:00
Check `REDIRECT_URIS` in `settings.py` , the final value should be `"http://localhost/account/login/oauth"` or sth similar. If you are specifying a port, add the port to the localhost address.
2023-07-25 16:38:00 -04:00
2023-08-10 16:01:40 -04:00
If any change was made to `REDIRECT_URIS` , existing apps registered in Mastodon are no longer valid, so delete the app record in the database:
2023-07-24 13:39:49 +02:00
```
2023-07-25 16:38:00 -04:00
delete from mastodon_mastodonapplication;
2023-07-24 13:39:49 +02:00
```