- Setup of Local PostgreSQL Database
- Set up a Test User on Local Replate Database (before OAuth)
- OCR Tesseract Setup
Follow these steps to set up a local PostgreSQL database for the Django project.
Make sure you have PostgreSQL installed on your system.
Create a PostgreSQL user if you haven’t already:
CREATE ROLE <YOUR_PSQL_USER> WITH LOGIN CREATEDB PASSWORD 'yourpassword';
Enter the psql shell:
psql postgres
Then create the database:
CREATE DATABASE replate OWNER <YOUR_PSQL_USER>;
Open settings.py and add the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': os.getenv('LOCAL_DB_HOST', 'localhost'),
'NAME': os.getenv('LOCAL_DB_NAME', 'replate'),
'USER': os.getenv('LOCAL_DB_USER'),
'PASSWORD': os.getenv('LOCAL_DB_PASSWORD'),
'PORT': os.getenv('LOCAL_DB_PORT', '5432'),
}
}
In your backend .env file (or .env.local), add the following values:
LOCAL_DB_HOST=localhost
LOCAL_DB_NAME=replate
LOCAL_DB_USER=<YOUR_PSQL_USER>
LOCAL_DB_PASSWORD=<YOUR_PASSWORD>
LOCAL_DB_PORT=5432
IMPORTANT: Replace <YOUR_PSQL_USER> and <YOUR_PASSWORD> with your PostgreSQL credentials. Make sure .env is NOT committed to Git to keep passwords safe.
Make sure you've pulled the latest models.py from origin/main first!
Navigate to the Django project root (e.g., /backend) and run:
python manage.py migrate # apply migrations to your PostgreSQL database
Connect to your database:
psql -U <YOUR_PSQL_USER> -d replate
If the prompt shows replate=#, you are in the correct database.
List all tables:
\dt
Type \q to exit the psql shell.
Setup complete! Your local PostgreSQL database is now ready and connected.
For local testing before implementing OAuth, you can create a test user with the provided script:
Script location: backend/api/utils/create_test_user.py
Run this script to create the test user.
This will create a test user with:
username: test
password: 123
You can verify that the API is working by making a simple GET request to list inventory items of the test user:
curl -u test:123 http://127.0.0.1:8000/api/items/
You should get a JSON response (an empty list [] if no items exist yet)
This confirms that your local Django backend and test user are set up correctly.
The OCR functionality requires both the Tesseract executable and the Python wrapper pytesseract.
- Install Tesseract
macOS (using Homebrew):
brew install tesseract
Ubuntu/Debian:
sudo apt update
sudo apt install tesseract-ocr
Windows: Download the installer from Tesseract at UB Mannheim and add the installation directory to your PATH.
Verify installation:
tesseract --version
- Install Python Wrapper
Inside your activated virtual environment, install pytesseract (already stated in requirements.txt):
pip install -r requirements.txt
- Test OCR Endpoint
After setting up Tesseract, you can test the OCR upload endpoint with a sample image:
curl -u test:123 -X POST http://127.0.0.1:8000/api/ocr/scan/ \
-F "image=/path/to/expiry_label.jpg"
Expected response: JSON containing the detected date(s) and any extracted text.