|
1 | 1 | # NyaaV2
|
2 | 2 |
|
3 |
| -## Setup: |
4 |
| - |
5 |
| -- Create your virtualenv, for example with `pyvenv venv` |
6 |
| -- Enter your virtualenv with `source venv/bin/activate` |
7 |
| -- Install dependencies with `pip install -r requirements.txt` |
8 |
| -- Run `python db_create.py` to create the database |
9 |
| -- Start the dev server with `python run.py` |
10 |
| - |
11 |
| -## Updated Setup (python 3.6.1): |
| 3 | +## Setup |
12 | 4 |
|
13 | 5 | - Install dependencies https://github.com/pyenv/pyenv/wiki/Common-build-problems
|
14 | 6 | - Install `pyenv` https://github.com/pyenv/pyenv/blob/master/README.md#installation
|
|
20 | 12 | - Copy `config.example.py` into `config.py`
|
21 | 13 | - Change TABLE_PREFIX to `nyaa_` or `sukebei_` depending on the site
|
22 | 14 |
|
23 |
| -## Setting up MySQL/MariaDB database for advanced functionality |
| 15 | +### Setting up MySQL/MariaDB database for advanced functionality |
24 | 16 | - Enable `USE_MYSQL` flag in config.py
|
25 | 17 | - Install latest mariadb by following instructions here https://downloads.mariadb.org/mariadb/repositories/
|
26 | 18 | - Tested versions: `mysql Ver 15.1 Distrib 10.0.30-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2`
|
|
35 | 27 | - `CREATE DATABASE nyaav2 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;`
|
36 | 28 | - `SOURCE ~/path/to/database/nyaa_maria_vx.sql`
|
37 | 29 |
|
38 |
| -## Finishing up |
| 30 | +### Finishing up |
39 | 31 | - Run `python db_create.py` to create the database
|
40 | 32 | - Load the .sql file
|
41 | 33 | - `mysql -u user -p nyaav2`
|
42 | 34 | - `SOURCE cocks.sql`
|
43 | 35 | - Remember to change the default user password to an empty string to disable logging in
|
44 | 36 | - Start the dev server with `python run.py`
|
45 |
| -- Deactivate `source deactivate` |
| 37 | +- When you are finished developing, deactivate your virtualenv with `source deactivate` |
46 | 38 |
|
47 |
| -# Enabling ElasticSearch |
| 39 | +## Enabling ElasticSearch |
48 | 40 |
|
49 |
| -## Basics |
| 41 | +### Basics |
50 | 42 | - Install jdk `sudo apt-get install openjdk-8-jdk`
|
51 | 43 | - Install elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html
|
52 | 44 | - `sudo systemctl enable elasticsearch.service`
|
53 | 45 | - `sudo systemctl start elasticsearch.service`
|
54 | 46 | - Run `curl -XGET 'localhost:9200'` and make sure ES is running
|
55 | 47 | - Optional: install Kabana as a search frontend for ES
|
56 | 48 |
|
57 |
| -## Enable MySQL Binlogging |
| 49 | +### Enable MySQL Binlogging |
58 | 50 | - Add the `[mariadb]` bin-log section to my.cnf and reload mysql server
|
59 | 51 | - Connect to mysql
|
60 | 52 | - `SHOW VARIABLES LIKE 'binlog_format';`
|
61 | 53 | - Make sure it shows ROW
|
62 | 54 | - Connect to root user
|
63 | 55 | - `GRANT REPLICATION SLAVE ON *.* TO 'test'@'localhost';` where test is the user you will be running `sync_es.py` with
|
64 | 56 |
|
65 |
| -## Setting up ES |
| 57 | +### Setting up ES |
66 | 58 | - Run `./create_es.sh` and this creates two indicies: `nyaa` and `sukebei`
|
67 | 59 | - The output should show `acknowledged: true` twice
|
68 | 60 | - The safest bet is to disable the webapp here to ensure there's no database writes
|
69 | 61 | - Run `python import_to_es.py` with `SITE_FLAVOR` set to `nyaa`
|
70 | 62 | - Run `python import_to_es.py` with `SITE_FLAVOR` set to `sukebei`
|
71 | 63 | - These will take some time to run as it's indexing
|
72 | 64 |
|
73 |
| -## Setting up sync_es.py |
| 65 | +### Setting up sync_es.py |
74 | 66 | - Sync_es.py keeps the ElasticSearch index updated by reading the BinLog
|
75 | 67 | - Configure the MySQL options with the user where you granted the REPLICATION permissions
|
76 | 68 | - Connect to MySQL, run `SHOW MASTER STATUS;`.
|
77 | 69 | - Copy the output to `/var/lib/sync_es_position.json` with the contents `{"log_file": "FILE", "log_pos": POSITION}` and replace FILENAME with File (something like master1-bin.000002) in the SQL output and POSITION (something like 892528513) with Position
|
78 | 70 | - Set up `sync_es.py` as a service and run it, preferably as the system/root
|
79 | 71 | - Make sure `sync_es.py` runs within venv with the right dependencies
|
80 | 72 |
|
81 |
| -## Good to go! |
82 |
| -- After that, enable the `USE_ELASTIC_SEARCH` flag and restart the webapp and you're good to go |
| 73 | +Enable the `USE_ELASTIC_SEARCH` flag in `config.py`, restart the application, and you're good to go. |
83 | 74 |
|
| 75 | +## Database migrations |
| 76 | +- Uses [flask-Migrate](https://flask-migrate.readthedocs.io/) |
| 77 | +- Run `./db_migrate.py db migrate` to generate the migration script after database model changes. |
| 78 | +- Take a look at the result in `migrations/versions/...` to make sure nothing went wrong. |
| 79 | +- Run `./db_migrate.py db upgrade` to upgrade your database. |
84 | 80 |
|
85 | 81 | ## Code Quality:
|
86 | 82 | - Remember to follow PEP8 style guidelines and run `./lint.sh` before committing.
|
0 commit comments