Dex Docs

Updating the Database

Updating the Database

This server uses a SQLite3 database created from the PokéAPI GitHub repo. If you would like to grab the most up-to-date database or clone your own to host your own server, you'll need to have Python3 installed. If you don't have it already, you can find the download on the Python website.

Here are some steps if following the instructions on the PokéAPI GitHub repo are unclear or aren't working:

  1. Clone the PokéAPI repo to your computer and open it up in your code editor
git clone https://github.com/PokeAPI/pokeapi.git
  1. **Skip this step if your pip and python commands are already running on pip3 and python3 respectively. If not, you might have to update the scripts -- navigate to Makefile at the root of the project. Here, we're going to update all of the script commands to use pip3 instead of pip so that we can use Python3. The updated file should look like this:
1.PHONY: help
2
3help:
4 @grep -E '^[a-zA-Z_-]+:.*?# .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?# "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
5
6
7install: # Install base requirements to run project
8 pip3 install -r requirements.txt
9
10dev-install: # Install developer requirements + base requirements
11 pip3 install -r test-requirements.txt
12
13setup: # Set up the project database
14 python3 manage.py migrate --settings=config.local
15
16wipe_db: # Delete's the project database
17 rm -rf db.sqlite3
18
19serve: # Run the project locally
20 python3 manage.py runserver --settings=config.local
21
22test: # Run tests
23 python3 manage.py test --settings=config.local
24
25clean: # Remove any pyc files
26 find . -type f -name '*.pyc' -delete
27
28migrate: # run any outstanding migrations
29 python3 manage.py migrate --settings=config.local
30
31shell: # Load a shell
32 python3 manage.py shell --settings=config.local
33
34format: # Format the source code
35 black .
36
37format-check: # Check the source code has been formatted
38 black . --check
  1. Now we can install the requirements
# this will install all of the required packages and libraries for using PokéAPI
make install
  1. Start up the Django shell
# Update the `python` script to use `python3` if necessary
python manage.py shell --settings=config.local
  1. Run the build script
from data.v2.build import build_all
build_all()
  1. The database will be found in the root of the project as db.sqlite3. You can now move this database file to your GraphQL Pokédex Server repo! Just replace the db.sqlite3 file in the server repo (src/data) with your new one.
Edit this page on GitHub